Boost logo

Boost :

Subject: Re: [boost] [type_traits] is_base_of<B, D> should work when B is incomplete
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2016-03-04 04:02:53

2016-03-03 23:18 GMT+01:00 Daniel Frey <d.frey_at_[hidden]>:

> > On 03.03.2016, at 22:57, Andrzej Krzemienski <akrzemi1_at_[hidden]> wrote:
> >
> > The Standard ([meta.rel]) requires that in std::is_base_of<B, D> D must
> be
> > a complete type, but it does not require the same of B. This makes sense,
> > because if we compare a complete type D and an incomplete type B, the
> > former is surely not derived from the latter.
> > In contrast, boost::is_base_of imposes an additional constraint that B
> must
> > also be complete. Could this restriction be lifted?
> That would probably be possible for all modern compilers that have a
> proper std::is_base_of because it requires a compiler intrinsic (unless you
> can implement it without such an intrinsic and in C++98). Boost.TypeTraits
> have quite a history and by lifting the restriction, you would drop support
> for old compilers (think pre-C++11).
> And if you really need this feature, why not use std::is_base_of directly?
> Either your compiler has it or it can’t be implemented AFAICT.

I need it for patching boost::optional. It must work on any system. I do
not know how to portably check if a given compiler defines std::is_base_of.

What I do not understand now is why the following small program compiles:

I also paste it here

#include <boost/core/enable_if.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include <iostream>

struct factory_base;

typedef char true_type;
typedef struct {char _[2];} false_type;

template <typename T>
typename boost::enable_if_c<!boost::is_base_of<factory_base, T>::value,
    fun(T&&) { puts("val"); return true_type(); }

template <typename T>
typename boost::enable_if_c<boost::is_base_of<factory_base, T>::value,
    fun(T&&) { puts("factory"); return false_type(); }

int main()

It can handle boost::is_base_of with an incomplete type. SFINAE should only
work on "surface" compilation errors. But boost::is_base_of has an explicit
static assertion INSIDE the body.


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