C++ Template Metaprogramming の Exercise 4-2

Variadic Templates Verで書いた。

struct error {};

template< bool B, typename ... Args >
struct logical_and_;
template< typename head, typename ... tail >
struct logical_and_<false, head, tail...>
{
	typedef mpl::false_ type;
};
template< typename head, typename ... tail >
struct logical_and_<true, head, tail...>
{
	typedef typename logical_and_<head::type::value, tail...>::type type;
};
template< typename T >
struct logical_and_<true, T>
{
	typedef typename T::type type;
};
template< typename head, typename ... tail >
struct logical_and
{
	static const bool value = head::type::value;
	typedef typename logical_and_<value, tail...>::type type;
};

template< bool B, typename ... Args >
struct logical_or_;
template< typename head, typename ... tail >
struct logical_or_<false, head, tail...>
{
	typedef typename logical_or_<head::type::value, tail...>::type type;
};
template< typename T >
struct logical_or_<false, T>
{
	typedef typename T::type type;
};
template< typename head, typename ... tail >
struct logical_or_<true, head, tail...>
{
	typedef mpl::true_ type;
};
template< typename head, typename ... tail >
struct logical_or
{
	static const bool value = head::type::value;
	typedef typename logical_or_<value, tail...>::type type;
};


int main()
{
	BOOST_STATIC_ASSERT(( logical_or<mpl::true_, error>::type::value ));
	BOOST_STATIC_ASSERT(( !logical_and<mpl::false_, error>::type::value ));
	
	BOOST_STATIC_ASSERT(( logical_or<mpl::false_, mpl::false_, mpl::true_, error>::type::value ));
	BOOST_STATIC_ASSERT(( !logical_and<mpl::true_, mpl::true_, mpl::false_, error>::type::value ));
}

まだ慣れてない。