32#ifndef KBLIB_TRAITS_H_INCLUDED_
33#define KBLIB_TRAITS_H_INCLUDED_
51template <
typename Tuple,
typename T>
54template <
typename T,
typename U,
typename... Ts>
58template <
typename T,
typename... Ts>
64template <
typename... Ts>
71template <
typename Lhs,
typename Rhs>
74template <
typename Tuple,
typename T,
typename... Ts>
76 : std::integral_constant<
77 bool, contains_type<Tuple, T>::value
78 and contains_types<Tuple, std::tuple<Ts...>>::value> {};
80template <
typename Tuple>
83template <
typename... Ts>
89template <
template <
typename...>
class Tuple,
typename... Ts>
91 using type = std::tuple<Ts...>;
104 template <
typename T,
int N,
int... I>
106 std::integer_sequence<int, I...>)
119template <
int trim,
typename T,
int N,
120 typename Indices = std::make_integer_sequence<int, N - trim>>
122 -> std::array<T, N - trim> {
134template <
int N,
typename Indices = std::make_integer_sequence<int, N - 1>>
136 -> std::array<char, N - 1> {
147template <
typename T, std::
size_t N>
160template <
typename,
typename T>
168template <
typename U,
typename T>
181template <
typename T,
typename F>
184 sizeof(T) ==
sizeof(F),
185 "Source and destination types for byte_cast must be the same size.");
186 static_assert(std::is_trivially_copyable<T>::value
187 and std::is_trivially_copyable<F>::value,
188 "Source and destination types for byte_cast must be trivially "
191 std::memcpy(&ret, &v,
sizeof(T));
197 template <typename C, typename = decltype(std::declval<C&>().resize(0))>
200 template <typename C, int = std::tuple_size<C>::value>
219template <
typename C,
typename =
void>
224 has_reserve_v<C, void_t<decltype(std::declval<C&>().reserve(0))>> =
true;
238template <
typename C,
typename std::enable_if<has_reserve_v<C>,
int>::type = 0>
239auto try_reserve(C& c, std::size_t s)
noexcept(
noexcept(c.reserve(s))) ->
void {
251 typename std::enable_if<not has_reserve_v<C>,
int>::type = 0>
252auto try_reserve(C&, std::size_t)
noexcept ->
void {
260template <
typename C,
typename =
void>
265 is_contiguous_v<C, void_t<decltype(std::declval<C&>().data())>> =
true;
273template <
typename T,
typename M>
281#if __cpp_nontype_template_parameter_auto
284using class_t =
typename class_of<
decltype(M)>::type;
291template <
typename T,
typename M>
299#if __cpp_nontype_template_parameter_auto
304template <
typename, auto M>
311template <
typename R,
typename... Args>
314template <
typename R,
typename... Args>
317template <
typename R,
typename... Args>
320template <
typename R,
typename... Args>
326template <
typename T,
typename =
void>
332 std::input_iterator_tag,
333 typename std::iterator_traits<T>::iterator_category>::value>>
339template <
typename T,
typename =
void>
345 std::forward_iterator_tag,
346 typename std::iterator_traits<T>::iterator_category>::value>>
352template <
typename T,
typename =
void>
358 std::bidirectional_iterator_tag,
359 typename std::iterator_traits<T>::iterator_category>::value>>
366template <
typename T,
typename =
void>
372 std::random_access_iterator_tag,
373 typename std::iterator_traits<T>::iterator_category>::value>>
384template <
typename Range,
typename =
void>
386template <
typename T, std::
size_t N>
390template <
typename Range>
392 void_t<decltype(begin(
std::declval<Range&>()))>> {
393 using type =
decltype(begin(std::declval<Range&>()));
396template <
typename Range>
399template <
typename Range,
typename =
void>
402template <
typename Range>
404 begin(
std::declval<Range&>()))>::value>>
407template <
typename T, std::
size_t N>
409template <
typename T, std::
size_t N>
415template <
typename T,
typename =
void>
420 T,
void_t<decltype(*std::declval<T&>(), void(), ++std::declval<T&>())>>
443template <
typename CharT =
char>
446template <
typename T, T V>
448 constexpr operator T() const noexcept {
return V; }
449 static constexpr T value = V;
452#if __cpp_nontype_template_parameter_auto
This header provides some features of C++17 <type_traits> and other headers for C++14,...
auto calc_resizable(...) noexcept -> std::false_type
typename make_void< Ts... >::type void_t
constexpr auto size(const C &c) -> decltype(c.size())
constexpr auto trim_array(const T(&arr)[N]) -> std::array< T, N - trim >
Truncates the last trim elements from an array.
KBLIB_CONSTANT_V is_input_iterator_v
typename ignore< U, T >::type ignore_t
An alias for ignore<U, T>::type.
KBLIB_CONSTANT_V contains_type_v
KBLIB_CONSTANT_V is_iterable_v
typename std::remove_reference< T >::type remove_reference_t
Abbreviated name for std::remove_reference<T>::type for C++14.
typename iterator_type_for< Range >::type iterator_type_for_t
KBLIB_CONSTANT_V is_reference_v
Abbreviated name for std::is_reference<T>::value for C++14.
auto try_reserve(C &c, std::size_t s) noexcept(noexcept(c.reserve(s))) -> void
Attempt to reserve capacity in a container. No-op if unsupported.
KBLIB_CONSTANT_V is_iterator_v
KBLIB_CONSTANT_V contains_types_v
typename member_of< T >::type member_of_t
KBLIB_CONSTANT_V is_forward_iterator_v
T alias
A simple identity alias for simplifying some compound type declarations, such as function pointers.
KBLIB_CONSTANT_V is_resizable_v
constexpr auto remove_null_terminator(const char(&arr)[N]) -> std::array< char, N - 1 >
Creates an array of only the meaningful characters in a string literal, and not the null terminator.
KBLIB_CONSTANT_V is_random_access_iterator_v
KBLIB_CONSTANT_V is_aliasing_type_v
std::integral_constant< bool, v > bool_constant
typename void_if< b >::type void_if_t
KBLIB_CONSTANT_V is_bidirectional_iterator_v
typename class_of< T >::type class_of_t
KBLIB_CONSTANT_V is_contiguous_v
Type trait to determine if a container is contiguous.
KBLIB_CONSTANT_V has_reserve_v
auto byte_cast(F v) noexcept -> T
Creates a T with the same object representation as the given F.
KBLIB_CONSTANT auto eof
Names the EOF value for the given character type in std::char_traits.
Determines if T is a type in Tuple, which must be a std::tuple.
Determines if Lhs contains all of the types in Rhs, where both are std::tuples.
True if and only if C contains an accessible reserve() member.
Ignores its first template argument entirely, and returns its second.
decltype(begin(std::declval< Range & >())) type
Type trait that determines the iterator type for a range.
Provides macros and basic templates used by the rest of kblib.
#define KBLIB_NODISCARD
This internal macro is used to provide a fallback for [[nodiscard]] in C++14.