|
Boost : |
Subject: Re: [boost] [type_traits] Rewrite and dependency free version
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2015-01-14 16:33:57
El 14/01/2015 a las 20:58, John Maddock escribió:
> I'm going to throw this out there to see what folks think:
>
> In a branch called "Version2", see
> https://github.com/boostorg/type_traits/tree/Version2 is a partially
> rewritten type_traits lib: it doesn't yet contain all the traits of the
> old one, but there's a pretty good selection to test.
Very nice.
> The main pros for this version are:
>
> 1) Zero dependencies other than Boost.Config.
We still have Boost.PP.
> 4) Substantially reduced #includes - the aim is that all files should
> include only what they need and no more - with what's needed determined
> by the actual implementation variant when appropriate. There were also
> a lot of spurious #includes left over from old workarounds no longer used.
For "is_function", you might test (I could help once things are
stabilized) another approach that could avoid the use of Boost.PP:
//For a function to pointer an lvalue of function type T
//can be implicitly converted to a prvalue
//pointer to that function. This does not apply to
//non-static member functions because lvalues
//that refer to non-static member functions do not exist.
template <class T>
struct is_reference_convertible_to_pointer
{
struct twochar { char dummy[2]; };
template <class U> static char test(U*);
template <class U> static twochar test(...);
static T& source();
static const bool value = sizeof(char) == sizeof(test<T>(source()));
};
//Filter out:
// - class types that might have implicit conversions
// - void (to avoid forming a reference to void later)
// - references (e.g.: filtering reference to functions)
// - nullptr_t (convertible to pointer)
template < class T
, bool Filter = is_class_or_union<T>::value ||
is_void<T>::value ||
is_reference<T>::value ||
is_nullptr_t<T>::value >
struct is_function_impl
{ static const bool value =
is_reference_convertible_to_pointer<T>::value; };
template <class T>
struct is_function_impl<T, true>
{ static const bool value = false; };
template <class T>
struct is_function
: is_function_impl<T>
{};
This could allow us to avoid the preprocessor also in
"is_member_function_pointer":
template <class T>
struct is_member_function_pointer_cv
{
static const bool value = false;
};
template <class T, class C>
struct is_member_function_pointer_cv<T C::*>
: is_function<T>
{};
template <class T>
struct is_member_function_pointer
: is_member_function_pointer_cv<typename remove_cv<T>::type>
{};
Best,
Ion
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk