1

Here is the definition of __dependent_type:

template <class _Tp, bool>
struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};

All use cases:

/usr/.../c++/v1 >>> rg "_dependent_type"                                                                                                                      
memory
2211:          __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2212:          __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2402:      typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2406:      typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2410:      typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2412:  template <bool _Dummy, class _Deleter = typename __dependent_type<
2671:      typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2675:      typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2679:      typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2681:  template <bool _Dummy, class _Deleter = typename __dependent_type<

variant
1134:            enable_if_t<__dependent_type<is_default_constructible<__first_type>,
1292:              __dependent_type<is_move_constructible<_Types>, _Dummy>::value &&
1293:              __dependent_type<is_swappable<_Types>, _Dummy>::value)...>::value,

tuple
621:            __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...>

Question:

Isn't

template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};

and

 __dependent_type<is_default_constructible<_T1>>::value

enough?

Why does libcxx need this dummy bool?

Chen Li
  • 4,824
  • 3
  • 28
  • 55

1 Answers1

2

It is the dummy bool that makes the type dependent, this is the whole point of __dependent_type, otherwise you can just use the type itself.

Take this code as example:

  template <bool _Dummy>
  using _GoodRValRefType =
      typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;

Without the dummy to make it a dependent type, when the class template gets instantiated, _DeleterSFINAE::__good_rval_ref_type might cause a hard error, because not all of the _DeleterSFINAE has a __good_rval_ref_type member.

The dependent type delays evaluation, so that you can use _GoodRValRefType in a SFINAE context later.

llllllllll
  • 16,169
  • 4
  • 31
  • 54