Skip to content

Commit 6b23610

Browse files
authored
Deduce types traits based on if compiler builtins are present
1 parent e3dac1e commit 6b23610

File tree

1 file changed

+133
-139
lines changed

1 file changed

+133
-139
lines changed

include/etl/type_traits.h

Lines changed: 133 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,142 +1830,7 @@ typedef integral_constant<bool, true> true_type;
18301830
using is_trivially_copyable = etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>;
18311831
#endif
18321832

1833-
#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS)
1834-
1835-
//*********************************************
1836-
// Use the compiler's builtins.
1837-
//*********************************************
1838-
1839-
//*********************************************
1840-
// is_assignable
1841-
template<typename T1, typename T2>
1842-
struct is_assignable
1843-
{
1844-
static ETL_CONSTANT bool value = __is_assignable(T1, T2);
1845-
};
1846-
1847-
#if ETL_USING_CPP11
1848-
//*********************************************
1849-
// is_constructible
1850-
template<typename T, typename... TArgs>
1851-
struct is_constructible
1852-
{
1853-
static ETL_CONSTANT bool value = __is_constructible(T, TArgs...);
1854-
};
1855-
#else
1856-
//*********************************************
1857-
// is_constructible
1858-
template<typename T, typename TArgs = void>
1859-
struct is_constructible
1860-
{
1861-
static ETL_CONSTANT bool value = __is_constructible(T, TArgs);
1862-
};
1863-
1864-
//*********************************************
1865-
// is_constructible
1866-
template<typename T>
1867-
struct is_constructible<T, void>
1868-
{
1869-
static ETL_CONSTANT bool value = __is_constructible(T);
1870-
};
1871-
#endif
1872-
1873-
//*********************************************
1874-
// is_copy_constructible
1875-
template <typename T>
1876-
struct is_copy_constructible : public etl::is_constructible<T, typename etl::add_lvalue_reference<const T>::type>
1877-
{
1878-
};
1879-
1880-
//*********************************************
1881-
// is_move_constructible
1882-
template <typename T>
1883-
struct is_move_constructible : public etl::is_constructible<T, T>
1884-
{
1885-
};
1886-
1887-
#if ETL_USING_CPP11
1888-
//*********************************************
1889-
// is_trivially_constructible
1890-
template <typename T, typename... TArgs>
1891-
struct is_trivially_constructible
1892-
{
1893-
#if defined(ETL_COMPILER_GCC)
1894-
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
1895-
#else
1896-
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs...);
1897-
#endif
1898-
};
1899-
#else
1900-
//*********************************************
1901-
// is_trivially_constructible
1902-
template <typename T, typename TArgs = void>
1903-
struct is_trivially_constructible
1904-
{
1905-
#if defined(ETL_COMPILER_GCC)
1906-
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
1907-
#else
1908-
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs);
1909-
#endif
1910-
};
1911-
1912-
//*********************************************
1913-
// is_trivially_constructible
1914-
template <typename T>
1915-
struct is_trivially_constructible<T, void>
1916-
{
1917-
#if defined(ETL_COMPILER_GCC)
1918-
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
1919-
#else
1920-
static ETL_CONSTANT bool value = __is_trivially_constructible(T);
1921-
#endif
1922-
};
1923-
#endif
1924-
1925-
//*********************************************
1926-
// is_trivially_copy_constructible
1927-
template <typename T>
1928-
struct is_trivially_copy_constructible : public is_trivially_constructible<T, typename add_lvalue_reference<const T>::type>
1929-
{
1930-
};
1931-
1932-
//*********************************************
1933-
// is_trivially_destructible
1934-
template <typename T>
1935-
struct is_trivially_destructible
1936-
{
1937-
#if defined(ETL_COMPILER_GCC)
1938-
static ETL_CONSTANT bool value = __has_trivial_destructor(T);
1939-
#else
1940-
static ETL_CONSTANT bool value = __is_trivially_destructible(T);
1941-
#endif
1942-
};
1943-
1944-
//*********************************************
1945-
// is_trivially_copy_assignable
1946-
template <typename T>
1947-
struct is_trivially_copy_assignable
1948-
{
1949-
#if defined(ETL_COMPILER_GCC)
1950-
static ETL_CONSTANT bool value = __has_trivial_copy(T);
1951-
#else
1952-
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
1953-
#endif
1954-
};
1955-
1956-
//*********************************************
1957-
// is_trivially_copyable
1958-
template <typename T>
1959-
struct is_trivially_copyable
1960-
{
1961-
#if defined(ETL_COMPILER_GCC)
1962-
static ETL_CONSTANT bool value = __has_trivial_copy(T);
1963-
#else
1964-
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
1965-
#endif
1966-
};
1967-
1968-
#elif defined(ETL_USER_DEFINED_TYPE_TRAITS) && !defined(ETL_USE_TYPE_TRAITS_BUILTINS)
1833+
#elif defined(ETL_USER_DEFINED_TYPE_TRAITS)
19691834

19701835
//*********************************************
19711836
// Force the user to provide specialisations for
@@ -2101,20 +1966,37 @@ typedef integral_constant<bool, true> true_type;
21011966
#else
21021967

21031968
//*********************************************
2104-
// Assume that anything other than arithmetics
2105-
// and pointers return false for the traits.
1969+
// Deduce traits based on if builtins exist.
21061970
//*********************************************
21071971

21081972
//*********************************************
21091973
// is_assignable
1974+
#if defined(ETL_USING_BUILTIN_IS_ASSIGNABLE) || defined(ETL_USE_TYPE_TRAITS_BUILTINS)
1975+
template<typename T1, typename T2>
1976+
struct is_assignable
1977+
{
1978+
static ETL_CONSTANT bool value = __is_assignable(T1, T2);
1979+
};
1980+
#else
21101981
template <typename T1, typename T2>
21111982
struct is_assignable : public etl::bool_constant<(etl::is_arithmetic<T1>::value || etl::is_pointer<T1>::value) && (etl::is_arithmetic<T2>::value || etl::is_pointer<T2>::value)>
21121983
{
21131984
};
1985+
#endif
21141986

21151987
#if ETL_USING_CPP11
1988+
#if defined(ETL_USING_BUILTIN_IS_CONSTRUCTIBLE) || defined(ETL_USE_TYPE_TRAITS_BUILTINS)
1989+
//*********************************************
1990+
// is_constructible
1991+
template<typename T, typename... TArgs>
1992+
struct is_constructible
1993+
{
1994+
static ETL_CONSTANT bool value = __is_constructible(T, TArgs...);
1995+
};
1996+
1997+
#else
21161998
//***************************************************************************
2117-
/// is_constructible
1999+
/// is_constructible_
21182000
namespace private_type_traits
21192001
{
21202002
template <class, class T, class... Args>
@@ -2128,6 +2010,7 @@ typedef integral_constant<bool, true> true_type;
21282010
// is_constructible
21292011
template <class T, class... Args>
21302012
using is_constructible = private_type_traits::is_constructible_<void_t<>, T, Args...>;
2013+
#endif
21312014

21322015
//*********************************************
21332016
// is_copy_constructible
@@ -2146,7 +2029,31 @@ typedef integral_constant<bool, true> true_type;
21462029
template <> struct is_move_constructible<void const volatile> : public false_type{};
21472030

21482031
#else
2032+
#if defined(ETL_USING_BUILTIN_IS_CONSTRUCTIBLE) || defined(ETL_USE_TYPE_TRAITS_BUILTINS)
2033+
//*********************************************
2034+
// is_constructible
2035+
template<typename T, typename TArgs = void>
2036+
struct is_constructible
2037+
{
2038+
static ETL_CONSTANT bool value = __is_constructible(T, TArgs);
2039+
};
2040+
2041+
//*********************************************
2042+
// is_constructible
2043+
template<typename T>
2044+
struct is_constructible<T, void>
2045+
{
2046+
static ETL_CONSTANT bool value = __is_constructible(T);
2047+
};
2048+
2049+
//*********************************************
2050+
// is_copy_constructible
2051+
template <class T> struct is_copy_constructible : public is_constructible<T, typename etl::add_lvalue_reference<typename etl::add_const<T>::type>::type>{};
21492052

2053+
//*********************************************
2054+
// is_move_constructible
2055+
template <typename T> struct is_move_constructible: public is_constructible<T, typename etl::add_rvalue_reference<T>::type>{};
2056+
#else
21502057
//*********************************************
21512058
// is_copy_constructible
21522059
template <typename T>
@@ -2161,7 +2068,53 @@ typedef integral_constant<bool, true> true_type;
21612068
{
21622069
};
21632070
#endif
2071+
#endif
21642072

2073+
#if defined(ETL_USING_BUILTIN_IS_TRIVIALLY_CONSTRUCTIBLE) || defined(ETL_USE_TYPE_TRAITS_BUILTINS)
2074+
#if ETL_USING_CPP11
2075+
//*********************************************
2076+
// is_trivially_constructible
2077+
template <typename T, typename... TArgs>
2078+
struct is_trivially_constructible
2079+
{
2080+
#if defined(ETL_COMPILER_GCC)
2081+
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
2082+
#else
2083+
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs...);
2084+
#endif
2085+
};
2086+
#else
2087+
//*********************************************
2088+
// is_trivially_constructible
2089+
template <typename T, typename TArgs = void>
2090+
struct is_trivially_constructible
2091+
{
2092+
#if defined(ETL_COMPILER_GCC)
2093+
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
2094+
#else
2095+
static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs);
2096+
#endif
2097+
};
2098+
2099+
//*********************************************
2100+
// is_trivially_constructible
2101+
template <typename T>
2102+
struct is_trivially_constructible<T, void>
2103+
{
2104+
#if defined(ETL_COMPILER_GCC)
2105+
static ETL_CONSTANT bool value = __has_trivial_constructor(T);
2106+
#else
2107+
static ETL_CONSTANT bool value = __is_trivially_constructible(T);
2108+
#endif
2109+
};
2110+
#endif
2111+
//*********************************************
2112+
// is_trivially_copy_constructible
2113+
template <typename T>
2114+
struct is_trivially_copy_constructible : public is_trivially_constructible<T, typename add_lvalue_reference<const T>::type>
2115+
{
2116+
};
2117+
#else
21652118
//*********************************************
21662119
// is_trivially_constructible
21672120
template <typename T>
@@ -2175,14 +2128,54 @@ typedef integral_constant<bool, true> true_type;
21752128
struct is_trivially_copy_constructible : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
21762129
{
21772130
};
2131+
#endif
21782132

2133+
#if defined(ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE) || defined(ETL_USE_TYPE_TRAITS_BUILTINS)
2134+
//*********************************************
2135+
// is_trivially_destructible
2136+
template <typename T>
2137+
struct is_trivially_destructible
2138+
{
2139+
#if defined(ETL_COMPILER_GCC)
2140+
static ETL_CONSTANT bool value = __has_trivial_destructor(T);
2141+
#else
2142+
static ETL_CONSTANT bool value = __is_trivially_destructible(T);
2143+
#endif
2144+
};
2145+
#else
21792146
//*********************************************
21802147
// is_trivially_destructible
21812148
template <typename T>
21822149
struct is_trivially_destructible : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
21832150
{
21842151
};
2152+
#endif
21852153

2154+
#if defined(ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE) || defined(ETL_USE_TYPE_TRAITS_BUILTINS)
2155+
//*********************************************
2156+
// is_trivially_copy_assignable
2157+
template <typename T>
2158+
struct is_trivially_copy_assignable
2159+
{
2160+
#if defined(ETL_COMPILER_GCC)
2161+
static ETL_CONSTANT bool value = __has_trivial_copy(T);
2162+
#else
2163+
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
2164+
#endif
2165+
};
2166+
2167+
//*********************************************
2168+
// is_trivially_copyable
2169+
template <typename T>
2170+
struct is_trivially_copyable
2171+
{
2172+
#if defined(ETL_COMPILER_GCC)
2173+
static ETL_CONSTANT bool value = __has_trivial_copy(T);
2174+
#else
2175+
static ETL_CONSTANT bool value = __is_trivially_copyable(T);
2176+
#endif
2177+
};
2178+
#else
21862179
//*********************************************
21872180
// is_trivially_copy_assignable
21882181
template <typename T>
@@ -2196,6 +2189,7 @@ typedef integral_constant<bool, true> true_type;
21962189
struct is_trivially_copyable : public etl::bool_constant<etl::is_arithmetic<T>::value || etl::is_pointer<T>::value>
21972190
{
21982191
};
2192+
#endif
21992193

22002194
#endif
22012195

0 commit comments

Comments
 (0)