0030550: Coding - Integer overflow in Standard_CString HashCodes
[occt.git] / src / Standard / Standard_Std.hxx
CommitLineData
2b2be3fb 1// Created on: 2019-03-27
2// Created by: Timur Izmaylov
3// Copyright (c) 2019 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _Standard_Std_HeaderFile
17#define _Standard_Std_HeaderFile
18
19
20#include <type_traits>
21
22
23//! Namespace opencascade is intended for low-level template classes and functions
24namespace opencascade
25{
26
27 //! Namespace opencascade::std includes templates from C++11 std namespace used by
28 //! OCCT classes. These definitions are imported from std namespace, plus (on older
29 //! compilers) from std::tr1, or implemented by custom code where neither std
30 //! not std::tr1 provide necessary definitions.
31 namespace std
32 {
33 // import all available standard stuff from std namespace
34 using namespace ::std;
35
36// for old MSVC compiler, some standard templates are defined in std::tr1 namespace,
37// and some missing ones are implemented here
38#if (defined(_MSC_VER) && (_MSC_VER < 1600))
39 using namespace ::std::tr1;
40
41 // C++11 template class enable_if
42 template <bool Test, class Type = void>
43 struct enable_if
44 { // type is undefined for assumed !_Test
45 };
46
47 template <class _Type>
48 struct enable_if<true, _Type>
49 { // type is _Type for _Test
50 typedef _Type type;
51 };
52
53 template <bool Condition, typename TypeTrue, typename TypeFalse>
54 struct conditional
55 {
56 typedef TypeTrue type;
57 };
58
59 template <typename TypeTrue, typename TypeFalse>
60 struct conditional<false, TypeTrue, TypeFalse>
61 {
62 typedef TypeFalse type;
63 };
64
65#endif
66
67 } // namespace std
68
69 //! Trait yielding true if class T1 is base of T2 but not the same
70 template <class T1, class T2, class Dummy = void>
71 struct is_base_but_not_same : opencascade::std::is_base_of<T1, T2>
72 {
73 };
74
75 //! Explicit specialization of is_base_of trait to workaround the
76 //! requirement of type to be complete when T1 and T2 are the same.
77 template <class T1, class T2>
78 struct is_base_but_not_same<T1,
79 T2,
80 typename opencascade::std::enable_if<opencascade::std::is_same<T1, T2>::value>::type>
81 : opencascade::std::false_type
82 {
83 };
84
85 //! The type trait that checks if the passed type is integer (it must be integral and not boolean)
86 //! @tparam TheInteger the checked type
87 template <typename TheInteger>
88 struct is_integer : std::integral_constant<bool,
89 opencascade::std::is_integral<TheInteger>::value
90 && !opencascade::std::is_same<TheInteger, bool>::value>
91 {
92 };
93
94 //! The auxiliary template that is used for template argument deduction in function templates. A function argument
95 //! which type is a template type parameter and it is not needed to be deducted must be declared using this class
96 //! template based on the type of some other template type parameter of a function template
97 //! @tparam TheType the type that is used as a function argument type to prevent its deduction
98 template <typename TheType>
99 struct disable_deduction
100 {
101 typedef TheType type;
102 };
103
104} // namespace opencascade
105
106#endif