boostorg / boostorg/type_traits
Better is_default_constructible in C++98
- Dominant language
- C++
- Stars
- 66
- Forks
- 87
- PR merge metrics
- No merged PRs in 30d
Description
- Lines 84 to 92 in boost/type_traits/is_default_constructible.hpp are the compromise solution without std::decltype. In fact, there are better solutions.
---
* The original code is as follows(line 84 ~ 92 in boost/type_traits/is_default_constructible.hpp)
```c++
// We don't know how to implement this, note we can not use has_trivial_constructor here
// because the correct implementation of that trait requires this one:
template struct is_default_constructible : public is_pod{};
template <> struct is_default_constructible : public integral_constant{};
template <> struct is_default_constructible : public integral_constant{};
template <> struct is_default_constructible : public integral_constant{};
template <> struct is_default_constructible : public integral_constant{};
```
* Better solution (without std::decltype or other C++11 feature)
```c++
// __is_default_constructible_helper
template
struct __is_default_constructible_helper
{
typedef char yes[1];
typedef char no[2];
template
static yes& check(int (*) [sizeof((U()))]);
template
static no& check(...);
static const bool value = sizeof(check(0)) == sizeof(yes);
};
// void : false
template
struct __is_default_constructible_helper
: public false_type { };
// T[S] -> T
template
struct __is_default_constructible_helper
: public __is_default_constructible_helper { };
// T[] : false
template
struct __is_default_constructible_helper
: public false_type { };
// T&& and T& : false
template
struct __is_default_constructible_helper
: public false_type { };
#if __cplusplus >= 201103L
template
struct __is_default_constructible_helper
: public false_type { };
#endif // __cplusplus >= 201103L
/// is_default_constructible
template
struct is_default_constructible
: public kim::bool_constant<
__is_default_constructible_helper<
typename kim::__remove_cv::type, !is_void::value
>::value
>::type
{ };
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.