I just finished the first exercise in the C++ meta programming book.
Then I checked what had been done before on this mailing list.
Here is my solution:
using namespace boost;
template
struct add_const_ref_impl
{
typedef T const & type;
};
template <typename T>
struct add_const_ref_impl
{
typedef T type;
};
template<class T>
struct add_const_ref
{
typedef typename add_const_ref_impl::type
type;
};
From Bruce Trask comes:
using namespace boost;
template<typename T>
struct add_const_ref
{
typedef typename add_reference::type type;
};
His solution is SO much better then mine.
However, when I first saw it I thought it must be wrong because I
assumed that add_const on a reference would would return a const reference.
In other words, the code below would be false:
bool a = is_same::type, int &>::value;
However! bool "a" is true. So my question is why is "a" true? Why
isn't add_const::type == int const &?
Thanks,
Chris