11 #ifndef BOGUS_CPP_TOOLS_HPP
12 #define BOGUS_CPP_TOOLS_HPP
21 #ifndef BOGUS_HAS_CPP11
22 #define BOGUS_HAS_CPP11 (__cplusplus >= 201103L)
27 #define BOGUS_NULL_PTR( Type ) nullptr
29 #define BOGUS_NULL_PTR( Type ) (static_cast<Type*>(0))
34 template <
bool DoSwap,
typename First_,
typename Second_ >
37 typedef First_ First ;
38 typedef Second_ Second ;
41 template <
typename First_,
typename Second_ >
44 typedef First_ Second ;
45 typedef Second_ First ;
48 template <
bool DoSwap,
int First_,
int Second_ >
51 enum { First = First_, Second = Second_ } ;
54 template <
int First_,
int Second_ >
55 struct SwapIf< true, First_, Second_ >
57 enum { First = Second_, Second = First_ } ;
61 template <
typename T1,
typename T2>
66 template <
typename T1 >
74 template <
bool Condition,
typename ReturnType_ =
void >
79 template <
typename ReturnType_ >
82 typedef ReturnType_ ReturnType ;
85 template <
bool Condition,
typename ReturnType_ =
void >
90 template <
typename ReturnType_ >
93 typedef ReturnType_ ReturnType ;
97 #define BOGUS_DEFINE_HAS_TYPE( TypeName ) \
98 template < typename BaseType > \
99 struct Has##TypeName \
102 enum { True = 1, False = 2 } ; \
103 typedef char TrueType[ True ] ; \
104 typedef char FalseType[ False ] ; \
105 template <typename T > struct Some { typedef int Type ; } ; \
107 template< typename T > \
108 static const TrueType& check( typename Some<typename T::TypeName>::Type ) ; \
109 template< typename > \
110 static const FalseType& check( ... ) ; \
112 enum { Value = ( True == sizeof( check< BaseType >( 0 ) ) ) } ;\
115 BOGUS_DEFINE_HAS_TYPE( ReturnType ) ;
116 BOGUS_DEFINE_HAS_TYPE( ConstTransposeReturnType ) ;
117 BOGUS_DEFINE_HAS_TYPE( Base ) ;
121 template <
bool Assertion >
125 BLOCKS_MUST_BE_SQUARE_OR_HAVE_DYNAMIC_DIMENSIONS,
126 BLOCKS_MUST_HAVE_FIXED_DIMENSIONS,
127 MATRICES_ORDERING_IS_INCONSISTENT,
128 TRANSPOSE_MAKES_NO_SENSE_IN_THIS_CONTEXT,
129 TRANSPOSE_IS_NOT_DEFINED_FOR_THIS_BLOCK_TYPE,
130 OPERANDS_HAVE_INCONSISTENT_FLAGS,
131 UNORDERED_INSERTION_WITH_COMPRESSED_INDEX,
141 #define BOGUS_STATIC_ASSERT( test, message ) (void) ::bogus::StaticAssert< test >::message
144 template<
typename Element >
150 enum { is_mutable = 0 } ;
153 : m_data( 0 ), m_size( 0 )
157 : m_data( data ), m_size( size )
160 void setData(
const Element* data, std::size_t size )
166 const Element* data()
const {
return m_data ; }
168 inline std::size_t size()
const {
return m_size ; }
169 inline bool empty()
const {
return 0 == m_size ; }
171 const Element* begin()
const {
return data() ; }
172 const Element* end()
const {
return data() + size() ; }
174 const Element& operator[]( std::size_t idx )
const
175 {
return m_data[idx] ; }
177 inline void resize( std::size_t s)
178 { assert( !m_data || m_size == s ) ; (void) s ; }
179 inline void reserve( std::size_t )
183 inline void assign( std::size_t s,
const Element&)
184 { assert( !m_data || m_size == s ) ; (void) s ; }
187 const Element* m_data ;
191 template<
typename Element >
198 template <
typename T,
typename Allocator>
199 inline const T* data_pointer(
const std::vector<T, Allocator>& vec )
204 return vec.empty() ? BOGUS_NULL_PTR(
const T ) : &vec[0] ;
209 template <
typename T,
typename Allocator>
210 inline T* data_pointer( std::vector<T, Allocator>& vec )
215 return vec.empty() ? BOGUS_NULL_PTR( T ) : &vec[0] ;
220 template<
typename Scalar>
225 inline bool has_element(
int )
const {
return true ; }
226 inline Scalar element(
int )
const {
return s ; }
227 inline Scalar operator[](
int )
const {
return s ; }
229 template<
typename Scalar>
Definition: CppTools.hpp:86
Definition: CppTools.hpp:122
Definition: CppTools.hpp:35
Definition: CppTools.hpp:221
Definition: CppTools.hpp:49
Definition: CppTools.hpp:62
Definition: CppTools.hpp:75
Const mapped array, used for Mapped Block Matrices.
Definition: CppTools.hpp:145