Boost logo

Boost Users :

From: Trask, Bruce (US SSA) (bruce.trask_at_[hidden])
Date: 2005-01-10 21:35:06


Philippe,

> Given that, it is trivial to modify Eric's solution to have the
> proper result.
>
Right. As they say in New England, Dawn in beginning to break over
Marblehead. It took me four cracks to get it, but I think I got it now
(see below and tell me if I do). (thanks for not telling me the answer
outright)

I starting to get the hang of it. Exercise 2.0 down. That's one in a
row :)

#include <iostream>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/static_assert.hpp>
using namespace std;

template<typename T>
struct add_const_ref
{
  typedef typename boost::add_reference<typename
boost::add_const<T>::type>::type type;
};

int main()
{

    BOOST_STATIC_ASSERT((boost::is_same<boost::add_const<int>::type,
const int>::value));
    BOOST_STATIC_ASSERT((boost::is_same<boost::add_reference<int>::type,
int&>::value));
    BOOST_STATIC_ASSERT((boost::is_same<boost::add_const<int&>::type,
int&>::value));
 
BOOST_STATIC_ASSERT((boost::is_same<boost::add_reference<boost::add_cons
t<int>::type>::type, int const&>::value));

    BOOST_STATIC_ASSERT((boost::is_same<add_const_ref<int&>::type,
int&>::value));
    BOOST_STATIC_ASSERT((boost::is_same<add_const_ref<int>::type, int
const&>::value));
    return 0;
}

Thanks for the input,
Bruce

> Philippe
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net