[Home]CPPTM Answers - Exercise 6-0

BOOST WIKI | RecentChanges | Preferences | Page List | Links List

No diff available--this is the first major revision. (no other diffs)
 // (by Ariel Badichi)
 #include <boost/static_assert.hpp>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/mpl/vector.hpp>
 #include <boost/mpl/copy.hpp>
 #include <boost/mpl/inserter.hpp>
 #include <boost/mpl/front.hpp>
 #include <boost/mpl/if.hpp>
 #include <boost/mpl/less.hpp>
 #include <boost/mpl/identity.hpp>
 #include <boost/mpl/sizeof.hpp>
 #include <boost/mpl/placeholders.hpp>

 namespace mpl = boost::mpl;
 using namespace mpl::placeholders;

 template<typename Prev, typename Element>
 struct smallest_op 
     : mpl::if_<
           typename mpl::less<
               mpl::sizeof_<Element>, 
               mpl::sizeof_<typename Prev::type> 
           >::type,
           mpl::identity<Element>,
           Prev
       >
 {
 };

 template<typename Seq>
 struct smallest 
     : mpl::copy<
           Seq, 
           mpl::inserter<
               mpl::identity<typename mpl::front<Seq>::type>, 
               smallest_op<_, _>
           > 
       >::type
 {
 };

 int main()
 {
     typedef mpl::vector<int[2], char, double &> v;
     typedef smallest<v>::type s;
     BOOST_STATIC_ASSERT((boost::is_same<s, char>::value));
     return 0;
 }

BOOST WIKI | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited March 27, 2005 11:46 am (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers