Corrade/Utility/TypeTraits.h file

Macros CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE, CORRADE_NO_STD_IS_TRIVIALLY_TRAITS, CORRADE_SOURCE_LOCATION_BUILTINS_SUPPORTED, CORRADE_HAS_TYPE(), alias Corrade::Utility::IsIterable.

Namespaces

namespace Corrade
Root namespace.
namespace Corrade::Utility
Utilities.

Typedefs

template<class T>
using IsIterable = std::integral_constant<bool, implementation-specific>
Traits class for checking whether given type is iterable.
template<class T>
using IsStringLike = std::integral_constant<bool, implementation-specific> new in 2019.10
Traits class for checking whether given type is string-like.

Defines

#define CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE new in 2020.06
Whether long double has the same precision as double
#define CORRADE_SOURCE_LOCATION_BUILTINS_SUPPORTED new in Git master
Whether source location builtins are supported.
#define CORRADE_NO_STD_IS_TRIVIALLY_TRAITS new in Git master
If the std::is_trivially_copyable family of type traits is not supported by the standard library.
#define CORRADE_STD_IS_TRIVIALLY_TRAITS_SUPPORTED deprecated in Git master
Whether the std::is_trivially_copyable family of type traits is supported by the standard library.
#define CORRADE_HAS_TYPE(className, ...)
Macro for creating traits class that checks for type expression validity.

Define documentation

#define CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE new in 2020.06

Whether long double has the same precision as double

Defined on platforms where the long double type has a 64-bit precision instead of 80-bit, thus same as double. It's the case for MSVC (source), 32-bit Android (no reliable source found, sorry), Emscripten and Mac (but not iOS) with ARM processors. Emscripten is a bit special because it's long double is sometimes 80-bit, but its precision differs from the 80-bit representation elsewhere, so it's always treated as 64-bit. Note that even though the type size and precision may be the same, these are still two distinct types, similarly to how int and signed int behave the same but are treated as different types.

#define CORRADE_SOURCE_LOCATION_BUILTINS_SUPPORTED new in Git master

Whether source location builtins are supported.

Defined if compiler-specific builtins used to implement the C++20 std::source_location feature are available. Defined on GCC at least since version 4.8, Clang 9+ and MSVC 2019 16.6 and newer; on all three they're present also in the C++11 mode. Used by:

#define CORRADE_NO_STD_IS_TRIVIALLY_TRAITS new in Git master

If the std::is_trivially_copyable family of type traits is not supported by the standard library.

The std::is_trivially_constructible, std::is_trivially_default_constructible, std::is_trivially_copy_constructible, std::is_trivially_move_constructible, std::is_trivially_assignable, std::is_trivially_copy_assignable, std::is_trivially_move_assignable family of traits is not implemented on libstdc++ below version 5. Instead, legacy std::has_trivial_default_constructor, std::has_trivial_copy_constructor and std::has_trivial_copy_assign are available, with slightly different semantics (see e.g. https://stackoverflow.com/q/12754886 for more information). From libstdc++ 5 onwards these are marked as deprecated and libstdc++ 7 removes them, so alternatively there are __has_trivial_constructor(), __has_trivial_copy() and __has_trivial_assign() builtins that don't produce any deprecated warnings and are available until GCC 9 / Clang 10 at least — however note that for SFINAE you need to wrap them in std::integral_constant as otherwise GCC would throw errors similar to the following:

error: use of built-in trait ‘__has_trivial_copy(T)’ in function signature; use library traits instead

This macro is defined if the standard variants are not available. Unfortunately, when libstdc++ is used through Clang, there's no way to check for its version until libstdc++ 7, which added the _GLIBCXX_RELEASE macro. That means, when using Clang with libstdc++ 5 or 6, it will still report those traits as being unavailable. Both libc++ and MSVC STL have these traits in all versions supported by Corrade, so there the macro is defined always.

#define CORRADE_STD_IS_TRIVIALLY_TRAITS_SUPPORTED

Whether the std::is_trivially_copyable family of type traits is supported by the standard library.

#define CORRADE_HAS_TYPE(className, ...)

Macro for creating traits class that checks for type expression validity.

Parameters
className Resulting class name
... Type expression to check. Variadic parameter to allow unrestricted usage of template expressions containing commas.

Defines a traits class checking whether an expression is valid. You can use T to reference the type which is being checked.

Usage examples: checking for presence of a key_type member typedef:

CORRADE_HAS_TYPE(HasKeyType, typename T::key_type);

static_assert(HasKeyType<std::map<int, int>>::value, "");
static_assert(!HasKeyType<std::vector<int>>::value, "");

Checking for presence of size() member function:

CORRADE_HAS_TYPE(HasSize, decltype(std::declval<T>().size()));

static_assert(HasSize<std::vector<int>>::value, "");
static_assert(!HasSize<std::tuple<int, int>>::value, "");