Add more type traits to CTL

This commit is contained in:
Justine Tunney 2024-06-30 20:59:38 -07:00
parent e437bed006
commit 44191b3f50
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 286 additions and 0 deletions

View file

@ -11,10 +11,12 @@ struct integral_constant
static constexpr T value = v;
typedef T value_type;
typedef integral_constant type;
constexpr operator value_type() const noexcept
{
return value;
}
constexpr value_type operator()() const noexcept
{
return value;

18
ctl/is_abstract.h Normal file
View file

@ -0,0 +1,18 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_ABSTRACT_H_
#define CTL_IS_ABSTRACT_H_
#include "integral_constant.h"
namespace ctl {
template<typename T>
struct is_abstract : public integral_constant<bool, __is_abstract(T)>
{};
template<typename T>
inline constexpr bool is_abstract_v = __is_abstract(T);
} // namespace ctl
#endif // CTL_IS_ABSTRACT_H_

18
ctl/is_base_of.h Normal file
View file

@ -0,0 +1,18 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_BASE_OF_H_
#define CTL_IS_BASE_OF_H_
#include "integral_constant.h"
namespace ctl {
template<typename Base, typename Derived>
struct is_base_of : public integral_constant<bool, __is_base_of(Base, Derived)>
{};
template<typename Base, typename Derived>
inline constexpr bool is_base_of_v = __is_base_of(Base, Derived);
} // namespace ctl
#endif // CTL_IS_BASE_OF_H_

18
ctl/is_class.h Normal file
View file

@ -0,0 +1,18 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_CLASS_H_
#define CTL_IS_CLASS_H_
#include "integral_constant.h"
namespace ctl {
template<typename T>
struct is_class : public integral_constant<bool, __is_class(T)>
{};
template<typename T>
inline constexpr bool is_class_v = __is_class(T);
} // namespace ctl
#endif // CTL_IS_CLASS_H_

19
ctl/is_constructible.h Normal file
View file

@ -0,0 +1,19 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_CONSTRUCTIBLE_H_
#define CTL_IS_CONSTRUCTIBLE_H_
#include "integral_constant.h"
namespace ctl {
template<class _Tp, class... _Args>
struct is_constructible
: public integral_constant<bool, __is_constructible(_Tp, _Args...)>
{};
template<class _Tp, class... _Args>
inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
} // namespace ctl
#endif // CTL_IS_CONSTRUCTIBLE_H_

18
ctl/is_empty.h Normal file
View file

@ -0,0 +1,18 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_EMPTY_H_
#define CTL_IS_EMPTY_H_
#include "integral_constant.h"
namespace ctl {
template<typename T>
struct is_empty : public integral_constant<bool, __is_empty(T)>
{};
template<typename T>
inline constexpr bool is_empty_v = __is_empty(T);
} // namespace ctl
#endif // CTL_IS_EMPTY_H_

18
ctl/is_enum.h Normal file
View file

@ -0,0 +1,18 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_ENUM_H_
#define CTL_IS_ENUM_H_
#include "integral_constant.h"
namespace ctl {
template<typename T>
struct is_enum : public integral_constant<bool, __is_enum(T)>
{};
template<typename T>
inline constexpr bool is_enum_v = __is_enum(T);
} // namespace ctl
#endif // CTL_IS_ENUM_H_

18
ctl/is_polymorphic.h Normal file
View file

@ -0,0 +1,18 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_POLYMORPHIC_H_
#define CTL_IS_POLYMORPHIC_H_
#include "integral_constant.h"
namespace ctl {
template<typename T>
struct is_polymorphic : public integral_constant<bool, __is_polymorphic(T)>
{};
template<typename T>
inline constexpr bool is_polymorphic_v = __is_polymorphic(T);
} // namespace ctl
#endif // CTL_IS_POLYMORPHIC_H_

19
ctl/is_standard_layout.h Normal file
View file

@ -0,0 +1,19 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_STANDARD_LAYOUT_H_
#define CTL_IS_STANDARD_LAYOUT_H_
#include "integral_constant.h"
namespace ctl {
template<typename T>
struct is_standard_layout
: public integral_constant<bool, __is_standard_layout(T)>
{};
template<typename T>
inline constexpr bool is_standard_layout_v = __is_standard_layout(T);
} // namespace ctl
#endif // CTL_IS_STANDARD_LAYOUT_H_

18
ctl/is_trivial.h Normal file
View file

@ -0,0 +1,18 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_TRIVIAL_H_
#define CTL_IS_TRIVIAL_H_
#include "integral_constant.h"
namespace ctl {
template<typename T>
struct is_trivial : public integral_constant<bool, __is_trivial(T)>
{};
template<typename T>
inline constexpr bool is_trivial_v = __is_trivial(T);
} // namespace ctl
#endif // CTL_IS_TRIVIAL_H_

18
ctl/is_union.h Normal file
View file

@ -0,0 +1,18 @@
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
#ifndef CTL_IS_UNION_H_
#define CTL_IS_UNION_H_
#include "integral_constant.h"
namespace ctl {
template<typename T>
struct is_union : public integral_constant<bool, __is_union(T)>
{};
template<typename T>
inline constexpr bool is_union_v = __is_union(T);
} // namespace ctl
#endif // CTL_IS_UNION_H_