OTest2
A C++ testing framework
typetraits.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Ondrej Starek
3  *
4  * This file is part of OTest2.
5  *
6  * OTest2 is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License,
9  * or (at your option) any later version.
10  *
11  * OTest2 is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OTest2__INCLUDE_OTEST2_TYPETRAITS_H_
20 #define OTest2__INCLUDE_OTEST2_TYPETRAITS_H_
21 
22 #include <cstddef>
23 #include <type_traits>
24 
25 namespace OTest2 {
26 
27 namespace Private {
28 
29 template<typename Type_, bool scalar_> struct SelectArgType;
30 template<typename Type_>
31 struct SelectArgType<Type_, true> {
32  typedef Type_ Value;
33 };
34 template<typename Type_>
35 struct SelectArgType<Type_, false> {
36  typedef const Type_& Value;
37 };
38 
39 } /* -- namespace Private */
40 
44 template<typename Type_>
45 struct TypeTrait {
47  typedef typename Private::SelectArgType<
48  Type_,
50 };
51 
56 template<typename Type_>
58  typedef Type_ Type;
59 };
60 template<std::size_t len_>
61 struct NormalizeStringType<char[len_]> {
62  typedef const char* Type;
63 };
64 template<std::size_t len_>
65 struct NormalizeStringType<const char[len_]> {
66  typedef const char* Type;
67 };
68 template<>
69 struct NormalizeStringType<char*> {
70  typedef const char* Type;
71 };
72 template<>
73 struct NormalizeStringType<const char*> {
74  typedef const char* Type;
75 };
76 
80 template<typename Type_>
82  typedef typename NormalizeStringType<
83  typename std::remove_const<
85 };
86 
87 } /* -- namespace OTest2 */
88 
89 #endif /* OTest2__INCLUDE_OTEST2_TYPETRAITS_H_ */
OTest2::Private::SelectArgType< Type_, true >::Value
Type_ Value
Definition: typetraits.h:32
OTest2::NormalizeStringType::Type
Type_ Type
Definition: typetraits.h:58
OTest2::NormalizeStringType< const char[len_]>::Type
const typedef char * Type
Definition: typetraits.h:66
OTest2::TypeTrait::BestArg
Private::SelectArgType< Type_, std::is_scalar< Type_ >::value >::Value BestArg
Definition: typetraits.h:49
OTest2::TypeTrait
Generic type trait used by the framework.
Definition: typetraits.h:45
OTest2::NormalizeStringType< char[len_]>::Type
const typedef char * Type
Definition: typetraits.h:62
OTest2::Private::SelectArgType< Type_, false >::Value
const typedef Type_ & Value
Definition: typetraits.h:36
OTest2
Definition: assertbean.h:25
OTest2::AssertionParameter::Type
NormalizeStringType< typename std::remove_const< typename std::remove_reference< Type_ >::type >::type >::Type Type
Definition: typetraits.h:84
OTest2::Private::SelectArgType
Definition: typetraits.h:29
OTest2::NormalizeStringType
A trait which is used to normalize types of string literals and C-strings.
Definition: typetraits.h:57
OTest2::NormalizeStringType< char * >::Type
const typedef char * Type
Definition: typetraits.h:70
OTest2::AssertionParameter
A helper trait - get normalized type of a captured assertion parameter.
Definition: typetraits.h:81
type
TokenType type
Definition: runnerfiltertags.cpp:502
value
std::string value
Definition: runnerfiltertags.cpp:503
OTest2::NormalizeStringType< const char * >::Type
const typedef char * Type
Definition: typetraits.h:74