mirror of
https://github.com/boostorg/parameter.git
synced 2026-01-19 04:22:13 +00:00
Every ArgumentPack is now a valid MPL Forward Sequence.
[SVN r32442]
This commit is contained in:
88
test/mpl.cpp
Executable file
88
test/mpl.cpp
Executable file
@@ -0,0 +1,88 @@
|
||||
// Copyright David Abrahams 2006. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "basics.hpp"
|
||||
#include <boost/mpl/list.hpp>
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/size.hpp>
|
||||
#include <boost/type_traits/add_pointer.hpp>
|
||||
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
# include <boost/mpl/find.hpp>
|
||||
# include <boost/mpl/end.hpp>
|
||||
|
||||
namespace test
|
||||
{
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
template <class Set>
|
||||
struct assert_in_set
|
||||
{
|
||||
template <class T>
|
||||
void operator()(T*)
|
||||
{
|
||||
#if 1 // mpl::set is too unreliable in this release.
|
||||
typedef typename mpl::find<Set,T>::type pos;
|
||||
typedef typename mpl::end<Set>::type not_found;
|
||||
BOOST_MPL_ASSERT_NOT((boost::is_same<pos, not_found>));
|
||||
#else
|
||||
BOOST_MPL_ASSERT((mpl::has_key<Set,T>));
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<class Expected, class Params>
|
||||
void f_impl(Params const& p BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected))
|
||||
{
|
||||
BOOST_MPL_ASSERT_RELATION(
|
||||
mpl::size<Expected>::value
|
||||
, ==
|
||||
, mpl::size<Params>::value
|
||||
);
|
||||
|
||||
mpl::for_each<Params, boost::add_pointer<mpl::_1> >(assert_in_set<Expected>());
|
||||
}
|
||||
|
||||
template<class Expected, class Tester, class Name, class Value, class Index>
|
||||
void f(Tester const& t, const Name& name_,
|
||||
const Value& value_, const Index& index_ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected))
|
||||
{
|
||||
f_impl<Expected>(f_parameters()(t, name_, value_, index_));
|
||||
}
|
||||
|
||||
template<class Expected, class Tester, class Name, class Value>
|
||||
void f(Tester const& t, const Name& name_, const Value& value_ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected))
|
||||
{
|
||||
f_impl<Expected>(f_parameters()(t, name_, value_));
|
||||
}
|
||||
|
||||
template<class Expected, class Tester, class Name>
|
||||
void f(Tester const& t, const Name& name_ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected))
|
||||
{
|
||||
f_impl<Expected>(f_parameters()(t, name_));
|
||||
}
|
||||
|
||||
|
||||
void run()
|
||||
{
|
||||
typedef test::tag::tester tester_;
|
||||
typedef test::tag::name name_;
|
||||
typedef test::tag::value value_;
|
||||
typedef test::tag::index index_;
|
||||
|
||||
f<mpl::list4<tester_,name_,value_,index_> >(1, 2, 3, 4);
|
||||
f<mpl::list3<tester_,name_,index_> >(1, 2, index = 3);
|
||||
f<mpl::list3<tester_,name_,index_> >(1, index = 2, name = 3);
|
||||
f<mpl::list2<name_,value_> >(name = 3, value = 4);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test::run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user