Boost logo

Boost Users :

Subject: [Boost-users] puzzle with enable_if
From: John Dlugosz (JDlugosz_at_[hidden])
Date: 2010-04-14 16:46:38


I'm using the Microsoft 2008 compiler.

The template

 template <typename T, typename D>
 struct is_proper_TD_types : std::tr1::integral_constant<bool,
    is_Universal_time_API<T>::value &&
      (std::tr1::is_same<typename T::duration_t,D>::value ||
       std::tr1::is_same<duration,D>::value ||
       std::tr1::is_same<linear_duration,D>::value ||
       is_dimensional_time<D>::value)
> {};

gives an error "'T': must be a class or namespace when followed by '::'" when T is int. This kind of thing is mentioned in the enable_if documentation as the motivation for the "lazy" forms, because the compiler doesn't apply SFINAE for other templates.

But, riddle me this: I created that line as an attempt to refactor the following, which DOES work OK:

 template <typename T, typename D>
 typename boost::enable_if_c<
   is_Universal_time_API<T>::value &&
   (std::tr1::is_same<typename T::duration_t,D>::value ||
    std::tr1::is_same<duration,D>::value ||
    std::tr1::is_same<linear_duration,D>::value ||
    is_dimensional_time<D>::value)
,T>::type
   operator+ (const T& t1, const D& d1)
 {
 // blah blah


Basically, I just copied the bulk of the first argument of enable_if_c in the second listing to make a named metaprogramming predicate that I could use in several places.

I don't see anything in your implementation of enable_if_c that would cause it to work: the argument is a template bool constant in both cases. Why does the bottom one work, when the top one doesn't?

--John







TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.


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