Boost logo

Boost Users :

From: Philippe Mori (philippe_mori_at_[hidden])
Date: 2005-01-10 19:29:13

> Dave Abrahams wrote:
>> Actually there's a much more concise solution using the type traits
>> library. That is, after all, the focus of the chapter.
> I believe that would be:
> template <typename T>
> struct add_const_ref {
> typedef add_const<add_ref<T>::type>::type type;
> };
> Correct me if I'm wrong.
> Eric.

This will not works because does not add const to references

For example:
    add_const<int &>::type; // type is int & and not int const &

I was not expecting that but it makes sence if we compare
references to const pointer:

add_const<int *>::type would give int * const and not int const *.

Since a reference in essentially equivalent to T * const (but
without the need of an inderection to uses it) add_const does
not have any effect in that case.

Given that, it is trivial to modify Eric's solution to have the
proper result.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at