libmoost
/home/mhx/git/github/libmoost/test/mpl/search.cpp
Go to the documentation of this file.
00001 /* vim:set ts=3 sw=3 sts=3 et: */
00031 #include <boost/mpl/list.hpp>
00032 #include <boost/test/unit_test.hpp>
00033 
00034 #include "../../include/moost/mpl/search.hpp"
00035 
00036 BOOST_AUTO_TEST_SUITE(mpl_search_test)
00037 
00038 namespace {
00039 
00040    typedef boost::mpl::list< long, short > tl_test;
00041 
00042    class finder
00043    {
00044    public:
00045       typedef size_t return_type;
00046 
00047       finder(size_t size)
00048          : m_size(size)
00049       {
00050       }
00051 
00052       template <class T>
00053       bool test() const
00054       {
00055          return m_size == sizeof(T);
00056       }
00057 
00058       template <class T>
00059       return_type found() const
00060       {
00061          return 2*sizeof(T);
00062       }
00063 
00064       return_type not_found() const
00065       {
00066          return 0;
00067       }
00068 
00069    private:
00070       const size_t m_size;
00071    };
00072 
00073 }
00074 
00075 BOOST_AUTO_TEST_CASE(mpl_search_policy_test)
00076 {
00077    BOOST_CHECK_EQUAL(moost::mpl::search<tl_test>(finder(1)), 0);
00078    BOOST_CHECK_EQUAL(moost::mpl::search<tl_test>(finder(sizeof(short))), 2*sizeof(short));
00079 }
00080 
00081 BOOST_AUTO_TEST_SUITE_END()