HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
type_traits.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: Apache-2.0
3 // https://github.com/AcademySoftwareFoundation/OpenImageIO
4 
5 // clang-format off
6 
7 /////////////////////////////////////////////////////////////////////////
8 // \file
9 // type_traits.h is where we collect little type traits and related
10 // templates.
11 /////////////////////////////////////////////////////////////////////////
12 
13 #pragma once
14 
16 #include <OpenImageIO/platform.h>
17 
19 
20 
21 // An enable_if helper to be used in template parameters which results in
22 // much shorter symbols: https://godbolt.org/z/sWw4vP
23 // Borrowed from fmtlib.
24 #ifndef OIIO_ENABLE_IF
25 # define OIIO_ENABLE_IF(...) std::enable_if_t<(__VA_ARGS__), int> = 0
26 #endif
27 
28 
29 // We use std::void_t as an aid to SFINAE. It's part of C++17, so prior to
30 // that we'll have to roll our own.
31 #if OIIO_CPLUSPLUS_VERSION >= 17 || defined(__cpp_lib_void_t)
32 using std::void_t;
33 #else
34 namespace pvt {
35 template<class... Ts> struct make_void { typedef void type; };
36 }
37 template<class... Ts> using void_t = typename pvt::make_void<Ts...>::type;
38 #endif
39 
40 
41 /// has_size_method<T>::value is true if T has a size() method and it returns
42 /// an integral type.
43 template<class, class = void> struct has_size_method : std::false_type { };
44 
45 template<class T>
46 struct has_size_method<T, void_t<decltype(std::declval<T&>().size())>>
47  : std::is_integral<typename std::decay_t<decltype(std::declval<T&>().size())>> { };
48 // How does this work? This overload is only defined if there is a size()
49 // method, and it evaluates to true_type or false_type based on whether size()
50 // returns an integral type.
51 
52 
53 /// has_subscript<T>::value is true if T has a subscript operator.
54 template<class, class = void> struct has_subscript : std::false_type { };
55 
56 template<class T>
57 struct has_subscript<T, void_t<decltype(std::declval<T&>()[0])>>
58  : std::true_type { };
59 
60 
61 
type
Definition: core.h:556
has_subscript<T>::value is true if T has a subscript operator.
Definition: type_traits.h:54
GLsizeiptr size
Definition: glcorearb.h:664
typename pvt::make_void< Ts...>::type void_t
Definition: type_traits.h:37
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:127
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:126