Boost logo

Boost :

Subject: Re: [boost] Pervasive dependency upon mpl::bool_
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2014-06-01 18:17:49


Le 01/06/14 22:40, Peter Dimov a écrit :
> We have lots of headers that depend on mpl::bool_ in order to define
> traits classes as deriving from mpl::true_ or mpl::false_.
>
> I don't think that this dependency is necessary even for MPL
> interoperability. The normal way of
>
> template<class T> struct trait
> {
> BOOST_STATIC_CONSTANT( bool, value = false );
> };
>
> should work just as well. I think.
>
> As one example, there's detail/blank.hpp, which starts with
>
> #include "boost/mpl/bool.hpp"
> #include "boost/type_traits/is_empty.hpp"
> #include "boost/type_traits/is_pod.hpp"
> #include "boost/type_traits/is_stateless.hpp"
>
> It doesn't really need these includes.
>
> namespace boost {
>
> struct blank
> {
> };
>
> // type traits specializations
> //
>
> template <>
> struct is_pod< blank >
> : mpl::true_
> {
> };
>
> This can be written as
>
> template<class T> struct is_pod;
>
> template<> struct is_pod< blank >
> {
> BOOST_STATIC_CONSTANT( bool, value = true );
> };
>
This will need boost/config.hpp
> which requires no includes.
>
> The problem is, though, that all type traits do derive from mpl::true_
> or mpl::false_, and I'm not sure if rewriting blank.hpp in the above
> manner is actually correct. Should type trait specializations always
> derive from mpl::true_ or mpl::false_? Will I break something if I
> specialize a type trait to not derive from mpl::bool_? Or is a nested
> ::value enough? Who knows. :-)
Currently the type traits derive from true_type or false_type.

      is_pod
      <http://www.boost.org/doc/libs/1_55_0/libs/type_traits/doc/html/boost_typetraits/reference/is_pod.html>

template <class T>
struct is_pod : public /|true_type <http://www.boost.org/doc/libs/1_55_0/libs/type_traits/doc/html/boost_typetraits/reference/integral_constant.html>-or-false_type <http://www.boost.org/doc/libs/1_55_0/libs/type_traits/doc/html/boost_typetraits/reference/integral_constant.html>|/ {};

The problem is that integral_constant inherits from mpl::integral_c.

I suggest to change the contents of integral_constant.hpp to something like

template <class T, T v>

struct integral_constant {

     static BOOST_CONSTEXPR const T value = v;

     typedef T value_type;

     typedef integral_constant type;

     BOOST_CONSTEXPR operator value_type() const {return value;}

     BOOST_CONSTEXPR value_type operator ()() const {return value;}

};

typedef integral_constant<bool, true> true_type;

typedef integral_constant<bool, false> false_type;

Then blank.hpp

#include <boost/type_traits/integral_constant.hpp>

...
template <class T> struct is_pod;

template <> struct is_pod< blank > : true_type {};

...

>
> But really, if a header, whose entire purpose is to define an empty
> struct, can't get by without including type traits and mpl, we've lost
> the dependency game before it's even started.
You are right, some refactoring is needed.

I propose to move this integral_constant.hpp file to Boost.Core.

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk