Chapter10.Boost.StaticAssert
http://boost.org/doc/html/boost_staticassert.html
コンパイル時に、型変数の値チェックとかできる。
かなり便利かも。
#include <iterator> #include <boost/static_assert.hpp> #include <boost/type_traits.hpp> template <class RandomAccessIterator > RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator to) { // this template can only be used with // random access iterators... typedef typename std::iterator_traits< RandomAccessIterator >::iterator_category cat; BOOST_STATIC_ASSERT((boost::is_convertible<cat, const std::random_access_iterator_tag&>::value)); // // detail goes here... return from; }