Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-01-23 12:56:40

On Wednesday 23 January 2002 12:50 pm, you wrote:
> I propose a very simple patch to ref.hpp which allows one to portably
> determine whether a type is a reference_wrapper, and to extract its "value
> type":
> There's a bunch of other code needed to make this useful, but it introduces
> a dependency on type_traits in the no-partial-spec. case, so I guess that
> should go in a separate file.
> I happen to need something exactly like this for Boost.Python. Thoughts?
> -Dave

I use the same thing in Boost.Function. From boost/function/function_base.hpp

      // Determine if the incoming argument is a reference_wrapper
      template<typename T>
      struct is_ref
        BOOST_STATIC_CONSTANT(bool, value = false);

      template<typename T>
      struct is_ref<reference_wrapper<T> >
        BOOST_STATIC_CONSTANT(bool, value = true);
#else // no partial specialization
      typedef char yes_type;
      typedef double no_type;
      no_type is_ref_tester(...);

      template<typename T>
      yes_type is_ref_tester(reference_wrapper<T>*);

      template<typename T>
      struct is_ref
        static T* t;
          value = (sizeof(is_ref_tester(t)) == sizeof(yes_type)));

I'd be glad to have any form of this code in ref.hpp, and get it out of


Boost list run by bdawes at, gregod at, cpdaniel at, john at