Boost logo

Boost Users :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2004-12-24 13:32:15


"Agoston Bejo" <gusz1_at_[hidden]> wrote

> template<typename T>
> struct value_type
> {
> typedef typename eval_if< is_arithmetic<T>,
> identity<T>, identity<typename T::value_type> >::type
>
> // ERROR
>
> type;
> };

In your example T::value_type is unconditionally evaluated, and eval_if will
not help you in this particular case. You have to ensure that T::value_type
is never mentioned in a template that can be possibly instantiated with a
type that doesn't have this typedef (eval_if does this for ::type). You can
either switch to using ::type instead of ::value_type, and then eval_if will
probably help you, or just try something more basic, for example:

template<typename T, typename IsAr> struct value_type_impl;

template<typename T>
struct value_type_impl<T, mpl::true_> : identity<T>
{};

template<typename T>
struct value_type_impl<T, mpl::false_> : identity<typename T::value_type>
{};

template<typename T>
struct value_type : value_type_impl<T, is_arithmetic<T>::type>
{};

HTH,

Arkadiy


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