Upload
others
View
22
Download
0
Embed Size (px)
Citation preview
bibi DocumentationRelease 0.1
mmha
November 30, 2016
Contents
1 Get the Code 3
2 Quick Example 5
3 Requirements 7
4 What is mostly working 9
5 What is not working 11
6 What would be nice in the future 13
7 Documentation 157.1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157.2 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167.3 Allocator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177.4 Chrono . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177.5 Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187.6 Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227.7 Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277.8 Random . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327.9 Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357.10 Type Traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
8 License 43
i
ii
bibi Documentation, Release 0.1
bibi is a small header-only library which tries to implement the C++ Standard Library concepts using the ConceptsLite TS Syntax. In contrary to already existing libraries like origin, cmcstl2 or range-v3 its goal is to implement theconcepts currently defined in the standard, therefore making it easy to introduce concepts to an existing codebase.
Contents 1
bibi Documentation, Release 0.1
2 Contents
bibi Documentation, Release 0.1
4 Chapter 1. Get the Code
CHAPTER 2
Quick Example
#include <bibi/Core.h>#include <bibi/Algorithm.h>#include <iostream>#include <vector>
using namespace bibi;
auto negate(Signed s) {return -s;
}
template<typename T>concept bool SignedArithmetic = Arithmetic<T> && Signed<T>;
template<SignedArithmetic... Num>auto negativeSum(Num... num) {
return (negate(num) + ...);}
int main() {std::vector<int> lst{10, 42, -3141};// Whoops, our predicate lacks a parameterbibi::sort(lst.begin(), lst.end(), [](auto &){ return true; });
std::cout << negativeSum(1, 2, 3.0, 4ll) << std::endl;return 0;
}
Resulting compiler output (gcc 7.0 trunk):
Comparison with calling std::sort directly:
5
bibi Documentation, Release 0.1
6 Chapter 2. Quick Example
CHAPTER 3
Requirements
• A compiler with support for the Concepts Lite TS (at the time of writing, this only applies to gcc >= 6.1)
• A C++14 compliant standard library
• CMake 3.6 - Older Versions are very likely to work
7
bibi Documentation, Release 0.1
8 Chapter 3. Requirements
CHAPTER 4
What is mostly working
• Allocator (although optional constraints are not implemented)
• Type Traits
• Core Concepts
• Iterator
• Chrono
• Random
• Thread
• The algorithm header
• A very early Boost.GIL implementation
9
bibi Documentation, Release 0.1
10 Chapter 4. What is mostly working
CHAPTER 5
What is not working
• The numerics header has not been started yet
• Container Concepts are lacking, to say the least
• TimedLockable and SharedTimedMutex are underconstrained (possibly a gcc bug?)
• Some Random Concepts are underconstrined due to a gcc bug (a workaround is possible, but not implementedyet)
• TrivialClock is underconstrained (does not recursively check the constraints)
11
bibi Documentation, Release 0.1
12 Chapter 5. What is not working
CHAPTER 6
What would be nice in the future
• More tests (a lot more)
• Extending the Library to some Boost Concepts, most notably Boost.graph and Boost.asio
• Extending to the Ranges TS or range-v3
13
bibi Documentation, Release 0.1
14 Chapter 6. What would be nice in the future
CHAPTER 7
Documentation
7.1 Getting Started
7.1.1 What are Concepts?
Take a look at this presentation by Andrew Sutton.
7.1.2 Where can I find the C++ Standard Concepts?
Most of them can be found on cppreference. Those missing can still be found in the C++ working draft, which isavaliable for free.
7.1.3 How do I include this library in my Project?
Don’t forget to enable the C++17 and Concepts TS support in your compiler (-std=c++1z -fconcepts in thecase of gcc).
Quick and Dirty
Copy the contents of the include directory into your project.
Using CMake (in-tree)
add_subdirectory() bibis root and link against the bibi::bibi target.
Using CMake (out-of-tree)
You can install the library:
mkdir bibi/buildcd bibi/buildcmake .. -DCMAKE_BUILD_TYPE=Releasemakesudo make install# Alternatively, on Arch Linux:
15
bibi Documentation, Release 0.1
cd bibimakepkg -si
Then you can use find_package(bibi) in your Project:
find_package(bibi REQUIRED)add_executable(mars_climate_orbiter main.cpp)target_link_libraries(mars_climate_orbiter PRIVATE bibi::bibi)# Note that -std=foo might interfere with CMAKE_CXX_STANDARD, unfortunately CMake does not support C++1z/C++17 by itselftarget_compile_options(mars_climate_orbiter PRIVATE -std=c++1z)
7.1.4 Structure of the Library
All files are located in the bibi directory. The namespaces try to resemble those of the standard library, so allconcepts can be found in the bibi namespace, the exception being bibi::chrono containing Clock andTrivialClock.
7.2 Algorithm
The Algorithm header contains thin wrappers around all STL algorithms contained in <algorithm>. The signaturesare the same, but the concept requirements are checked. This will usually get you better error messages when youare writing template-heavy code using the STL, while also being C++11/14 compliant simply by removing the bibidependency and switching from the bibi namespace to std.
#ifdef __cpp_concepts#include <bibi/Algorithm.h>namespace algo = bibi;#else#include <algorithm>namespace algo = std;#endif
#include <iostream>#include <iterator>#include <vector>
auto main() -> int{
auto list = std::vector<int>{4, 3, 2};algo::sort(list.begin(), list.end());algo::copy(list.begin(), list.end(), std::ostream_iterator<int>(std::cout, " "));
}
Since there is no difference between the signatures, this page does not contain any function prototypes. Use the C++reference of your choice for that.
Note that this header does not yet implement the Parallelism TS and does not implement random_shuffle.
16 Chapter 7. Documentation
bibi Documentation, Release 0.1
7.3 Allocator
7.3.1 Allocator
EqualityComparable
Allocator
CopyConstructible CopyAssignable MoveConstructible MoveAssignable
Requirements
requires(A a, A a1, A a2,typename std::allocator_traits<A>::size_type n,typename std::allocator_traits<A>::pointer ptr,typename std::allocator_traits<A>::const_pointer cptr,typename std::allocator_traits<A>::void_pointer vptr,typename std::allocator_traits<A>::const_void_pointer cvptr)
{typename A::value_type;{*ptr} -> typename A::value_type;{*cptr} -> std::add_const_t<typename A::value_type>;{a.allocate(n)} -> typename A::pointer;{a.deallocate(ptr, n)};{a1 != a2} -> bool;
}
7.4 Chrono
7.4.1 Clock
Arithmetic
Clock::rep
isSame
Clock::duration std::chrono::duration<Clock::rep, Clock::period>
isVariableSpecializationOf
std::intmax_t, Clock::period, std::ratio
Requirements
requires{
{C::is_steady} -> bool;{C::now()} -> typename C::time_point;
}
7.3. Allocator 17
bibi Documentation, Release 0.1
7.4.2 TrivialClock
Clock
TrivialClock TrivialClockNumeric
typename TrivialClock::rep
EqualityComparable LessThanComparable DefaultConstructible CopyConstructible CopyAssignable Destructible Numeric Swappable
7.5 Container
7.5.1 Container
DefaultConstructible
Container
Swappable CopyConstructible CopyAssignable
Requirements
requires(C a, C b, const C constant){
typename C::value_type;typename C::reference;typename C::const_reference;typename C::iterator;typename C::const_iterator;typename C::difference_type;typename C::size_type;
{(&a)->~C()} -> void;
{a.begin()} -> typename C::iterator;{constant.begin()} -> typename C::const_iterator;{constant.cbegin()} -> typename C::const_iterator;{a.end()} -> typename C::iterator;{constant.end()} -> typename C::const_iterator;{constant.cend()} -> typename C::const_iterator;
{a.size()} -> typename C::size_type;{a.max_size()} -> typename C::size_type;{a.empty()} -> bool;
}
18 Chapter 7. Documentation
bibi Documentation, Release 0.1
Additional Notes
Iff typename C::value_type satisfies EqualityComparable, Container also satisfiesEqualityComparable and implements operator!=.
7.5.2 ReversibleContainer
Container
ReversibleContainer
BidirectionalIterator
Container::iterator Container::const_iterator
Requirements
requires(C a){
typename C::reverse_iterator;typename C::const_reverse_iterator;
{a.rbegin()} -> typename C::reverse_iterator;{a.rend()} -> typename C::reverse_iterator;{a.crbegin()} -> typename C::const_reverse_iterator;{a.crend()} -> typename C::const_reverse_iterator;
}
7.5.3 AllocatorAwareContainer
Container
AllocatorAwareContainer
DefaultConstructible
Container::allocator_type
Allocator CopyConstructible
Container::value_type
Requirements
requires(C a,typename C::allocator_type m,C t)
{{a.get_allocator()} -> Allocator;{a.get_allocator()} -> typename C::allocator_type;
7.5. Container 19
bibi Documentation, Release 0.1
{C(m)} -> C;{C(t, m)} -> C;
}
7.5.4 SequenceContainer
Container
SequenceContainer
Requirements
requires(X && a,typename X::const_iterator p,typename X::const_iterator q,typename X::const_iterator q1,typename X::const_iterator q2,typename X::value_type *i, // Should be InputIteratortypename X::value_type *j, // Should be InputIteratorstd::initializer_list<typename X::value_type> il,typename X::size_type n,const typename X::value_type &&t,typename X::value_type &&rv)
{{X(n, t)};{X(i, j)};{X(i, j)};{X(il)};{a = il} -> X &;//{a.emplace(p,args)} -> typename X::iterator;{a.insert(p,t)} -> typename X::iterator;{a.insert(p,rv)} -> typename X::iterator;{a.insert(p,n,t)} -> typename X::iterator;{a.insert(p,i,j)} -> typename X::iterator;{a.insert(p, il)} -> typename X::iterator;{a.erase(q)} -> typename X::iterator;{a.erase(q1,q2)} -> typename X::iterator;{a.clear()} -> void;{a.assign(i,j)} -> void;{a.assign(il)} -> void;
20 Chapter 7. Documentation
bibi Documentation, Release 0.1
{a.assign(n,t)} -> void;{a.front()} -> typename X::const_reference;
}
Additional Notes
Currently SequenceContainer does not check for allocator awareness or emplace* functions. Requirements usingan InputIterator currently use a pointer instead.
7.5.5 AssociativeContainer
Container
AssociativeContainer
BinaryPredicate
Container::value_compare, Container::value_type
Requirements
requires(X a,X a2, // should be Tconst X b,typename X::value_type i,typename X::value_type j,typename X::const_iterator p,typename X::const_iterator q,typename X::iterator r,typename X::const_iterator q1,typename X::const_iterator q2,std::initializer_list<typename X::value_type> il,typename X::value_type t,typename X::key_type k,typename X::key_compare c)
{{X(c)};{X(i, j, c)};{X(i, j)};{X(il)};{a = il} -> X &;{a.key_comp()} -> typename X::key_compare;
}
7.5. Container 21
bibi Documentation, Release 0.1
7.5.6 UnorderedAssociativeContainer
AllocatorAwareContainer
UnorderedAssociativeContainer
Hash
Container::hasher, Container::key_type
BinaryPredicate
Container::key_equal, Container::key_type
Requirements
requires(X a,const X b,const X *i,const X *j,typename X::const_iterator p,typename X::const_iterator q2,typename X::const_iterator q,typename X::const_iterator q1,std::initializer_list<typename X::value_type> il,typename X::value_type t,typename X::key_type k,typename X::hasher hf,typename X::key_equal eq,typename X::size_type n,float z)
{typename X::mapped_type;typename X::local_iterator;typename X::const_local_iterator;
{X(n,hf,eq)};{X(n,hf)};{X(n,hf)};{X(i,j,n,hf,eq)};{X(i,j,n,hf)};{X(i,j,n)};{X(i,j)};{X(il)};{X(il,n)};{X(il,n,hf)};{X(il,n,hf,eq)};{X(b)};{a = b} -> X &;{a = il} -> X &;
}
7.6 Core
Core extends (and therefore includes) the Type Traits concepts.
22 Chapter 7. Documentation
bibi Documentation, Release 0.1
7.6.1 EqualityComparable
Requirements
requires(const T a, const T b){
{a == b} -> bool;};
7.6.2 LessThanComparable
Requirements
requires(const T a, const T b){
{a < b} -> bool;};
7.6.3 Callable
Requirements
requires(T t, Args &&... args){
{t(args...)} -> R;};
7.6.4 FunctionObject
Object
FunctionObject
7.6. Core 23
bibi Documentation, Release 0.1
Requirements
requires(T t, Args &&... args){
{t(args...)} -> R;};
7.6.5 Swappable
Requirements
requires(T t, T u) { {std::swap(t, u)}; } ||requires(T t, T u) { {swap(t, u)}; };
7.6.6 NullablePointer
EqualityComparable
NullablePointer
DefaultConstructible CopyConstructible CopyAssignable Destructible
Requirements
requires(T p, T q, nullptr_t np){
{p = np};{p = np};{p != q};{p == np};{np == p};{p != np};{np != p};
};
24 Chapter 7. Documentation
bibi Documentation, Release 0.1
7.6.7 Hash
FunctionObject
Hash
CopyConstructible Destructible
Requirements
requires(T h, Key k){
{h(k)} -> size_t;};
7.6.8 Predicate
Callable<T, bool, U>
Predicate
7.6. Core 25
bibi Documentation, Release 0.1
7.6.9 BinaryPredicate
Callable<T, bool, U, U>
BinaryPredicate
7.6.10 Compare
Callable<T, bool, U, U>
Compare
26 Chapter 7. Documentation
bibi Documentation, Release 0.1
7.7 Iterator
7.7.1 Iterator
CopyConstructible
Iterator
CopyAssignable Destructible Swappable
Requirements
requires(It r){
{*r};{++r} -> It &;
}
7.7.2 InputIterator
Iterator
InputIterator
EqualityComparable
Requirements
requires(It i, It j){
{i != j} -> bool;{*i} -> typename std::iterator_traits<It>::reference;{*i++} -> typename std::iterator_traits<It>::value_type;
7.7. Iterator 27
bibi Documentation, Release 0.1
//{i->m};}
7.7.3 OutputIterator
Iterator
OutputIterator
Requirements
requires(It r)//, Writable o, Writable a){
{++r} -> It &;{r++} -> It;//{*r = o};//{*r++ = o};
}
28 Chapter 7. Documentation
bibi Documentation, Release 0.1
7.7.4 ForwardIterator
InputIterator
ForwardIterator
DefaultConstructible OutputIterator
Requirements
requires(It r)//, Writable o, Writable a){
{++r} -> It &;{r++} -> It;//{*r = o};//{*r++ = o};
}
Additional Notes
Iff ForwardIterator satisfies OutputIterator, the type std::iterator_traits<It>::referenceis a const reference.
7.7.5 BidirectionalIterator
ForwardIterator
BidirectionalIterator
7.7. Iterator 29
bibi Documentation, Release 0.1
Requirements
requires(It a){
{--a} -> It &;{a--} -> It;{*a--} -> typename std::iterator_traits<It>::reference;
}
7.7.6 RandomAccessIterator
BidirectionalIterator
RandomAccessIterator
Requirements
requires(It i,It a,It b,It &r,typename std::iterator_traits<It>::difference_type n)
{{r + n} -> It;{a + n} -> It;{n + a} -> It;
{r -= n} -> It &;{i - n} -> It;{b - a} -> typename std::iterator_traits<It>::difference_type;{i[n]} -> typename std::iterator_traits<It>::reference;
}
30 Chapter 7. Documentation
bibi Documentation, Release 0.1
7.7.7 MutableIterator
InputIterator
MutableIterator
OutputIterator
7.7.8 ValueSwappable
Iterator
ValueSwappable
Requirements
requires(T t, T u) { {std::swap(*t, *u)}; } ||requires(T t, T u) { {swap(*t, *u) }; };
7.7. Iterator 31
bibi Documentation, Release 0.1
7.8 Random
7.8.1 SeedSequence
Unsigned
SeedSequence::result_type
DefaultConstructible
SeedSequence
Requirements
(sizeof(typename S::result_type) >= 4) &&requires(
const uint32_t *ib,const uint32_t *ie,uint32_t *rb,uint32_t *re,std::initializer_list<typename S::result_type> il,S q,const S r,int16_t *ob)
{{S(ib, ie)};{S(il)};{q.generate(rb,re)} -> void;{r.size()} -> size_t;{r.param(ob)} -> void;
}
Additional Notes
ib, ie in the above block should be InputIterator, but gcc crashes on implicit template instantiations.rb, re in the above block should be RandomAccessIterator, but gcc crashes on implicit template in-stantiations. ob in the above block should be OutputIterator, but gcc crashes on implicit template instan-tiations.
32 Chapter 7. Documentation
bibi Documentation, Release 0.1
7.8.2 UniformRandomBitGenerator
Unsigned
UniformRandomBitGenerator::result_type
Requirements
requires(G g){
{G::min()} -> typename G::result_type;{G::max()} -> typename G::result_type;{g()} -> typename G::result_type;
}
7.8.3 RandomNumberEngine
UniformRandomBitGenerator
RandomNumberEngine
DefaultConstructible CopyConstructible EqualityComparable
Requirements
requires(E e,E &v,const E x,const E y,typename E::result_type s,std::seed_seq q,unsigned long long z,std::ostream os,std::istream is)
{{E(x)};{E(s)};
7.8. Random 33
bibi Documentation, Release 0.1
{E(q)};{e.seed()} -> void;{e.seed(s)} -> void;{e.seed(q)} -> void;{e()} -> typename E::result_type;{e.discard(z)} -> void;{x != y} -> bool;{os << x} -> std::ostream &;{is >> x} -> std::istream &;
}
Additional Notes
q in the above block should be SeedSequence, but gcc crashes on implicit template instantiations.
7.8.4 RandomNumberEngineAdaptor
RandomNumberEngine
RandomNumberEngineAdaptor
Requirements
requires(E e){
{e.base()} -> RandomNumberEngine;}
34 Chapter 7. Documentation
bibi Documentation, Release 0.1
7.8.5 RandomNumberDistribution
DefaultConstructible
RandomNumberDistribution
CopyConstructible
RandomNumberDistribution::param_type
CopyAssignable EqualityComparable
Requirements
requires(D d,const D x,const D y,const typename D::param_type p,std::mt19937 g,std::mt19937 g1,std::mt19937 g2,std::ostream os,std::istream is)
{{D(p)};{d.reset()} -> void;{x.param()} -> typename D::param_type;{d.param(p)} -> void;{d(g)} -> typename D::result_type;{d(g, p)} -> typename D::result_type;{x.min()} -> typename D::result_type;{x.max()} -> typename D::result_type;{x != y} -> bool;{os << x} -> std::ostream &;{is >> x} -> std::istream &;
}
Additional Notes
g, g1, g2 in the above block should be UniformRandomBitGenerator, but gcc crashes on implicittemplate instantiations.
7.9 Thread
7.9.1 BasicLockable
Requirements
requires(L m){
{m.lock()};
7.9. Thread 35
bibi Documentation, Release 0.1
{m.unlock()};}
7.9.2 Lockable
BasicLockable
Lockable
Requirements
requires(L m){
{m.try_lock()} -> bool;};
7.9.3 TimedLockable
Lockable
TimedLockable
36 Chapter 7. Documentation
bibi Documentation, Release 0.1
Requirements
//requires(L m)//{
//{m.try_lock_for()};//{m.try_lock_until()};
//};
Additional Notes
Requirements are not yet inforced because gcc cannot handle implicit template instantiations in requires expres-sions.
7.9.4 Mutex
Lockable
Mutex
DefaultConstructible Destructible NOT CopyConstructible NOT CopyAssignable NOT MoveConstructible NOT MoveAssignable
7.9.5 TimedMutex
TimedLockable
TimedMutex
Mutex
7.9. Thread 37
bibi Documentation, Release 0.1
7.9.6 SharedMutex
Mutex
SharedMutex
Requirements
requires(M m){
{m.lock_shared()};{m.try_lock_shared()};{m.unlock_shared()};
}
7.9.7 SharedTimedMutex
TimedMutex
SharedTimedMutex
SharedMutex
Requirements
//requires(M m)//{
38 Chapter 7. Documentation
bibi Documentation, Release 0.1
//{m.try_lock_shared_for()};//{m.try_lock_shared_until()};
//};
Additional Notes
Requirements are not yet inforced because gcc cannot handle implicit template instantiations in requires expres-sions.
7.10 Type Traits
This header declares every C++14 type trait as a concept. Additionally, it provides constexpr functions for typerelationships, an additional is_specialization_of trait and C++17s as_const.
7.10.1 List of Type Traits
Primary type categories
template<typename T> concept bool Array = std::is_array<T>::value;template<typename T> concept bool Enum = std::is_enum<T>::value;template<typename T> concept bool FloatingPoint = std::is_floating_point<T>::value;template<typename T> concept bool Function = std::is_function<T>::value;template<typename T> concept bool Integral = std::is_integral<T>::value;template<typename T> concept bool LvalueReference = std::is_lvalue_reference<T>::value;template<typename T> concept bool MemberFunctionPointer = std::is_member_function_pointer<T>::value;template<typename T> concept bool MemberObjectPointer = std::is_member_object_pointer<T>::value;template<typename T> concept bool NullPointer = std::is_null_pointer<T>::value;template<typename T> concept bool Pointer = std::is_pointer<T>::value;template<typename T> concept bool RvalueReference = std::is_rvalue_reference<T>::value;template<typename T> concept bool Union = std::is_union<T>::value;template<typename T> concept bool Void = std::is_void<T>::value;
Composite type categories
template<typename T> concept bool Arithmetic = std::is_arithmetic<T>::value;template<typename T> concept bool Compound = std::is_compound<T>::value;template<typename T> concept bool Fundamental = std::is_fundamental<T>::value;template<typename T> concept bool MemberPointer = std::is_member_pointer<T>::value;template<typename T> concept bool Object = std::is_object<T>::value;template<typename T> concept bool Reference = std::is_reference<T>::value;template<typename T> concept bool Scalar = std::is_scalar<T>::value;
Type properties
template<typename T> concept bool Abstract = std::is_abstract<T>::value;template<typename T, typename U> concept bool Assignable = std::is_assignable<T, U>::value;template<typename T> concept bool Const = std::is_const<T>::value;template<typename T> concept bool Constructible = std::is_constructible<T>::value;template<typename T> concept bool CopyAssignable = std::is_copy_assignable<T>::value;
7.10. Type Traits 39
bibi Documentation, Release 0.1
template<typename T> concept bool CopyConstructible = std::is_copy_constructible<T>::value;template<typename T> concept bool DefaultConstructible = std::is_default_constructible<T>::value;template<typename T> concept bool Destructible = std::is_destructible<T>::value;template<typename T> concept bool Empty = std::is_empty<T>::value;template<typename T> [[deprecated("Deprecated in C++17")]] concept bool LiteralType = std::is_literal_type<T>::value;template<typename T> concept bool MoveAssignable = std::is_move_assignable<T>::value;template<typename T> concept bool MoveConstructible = std::is_move_constructible<T>::value;template<typename T, typename U> concept bool NothrowAssignable = std::is_nothrow_assignable<T, U>::value;template<typename T> concept bool NothrowConstructible = std::is_nothrow_constructible<T>::value;template<typename T> concept bool NothrowCopyAssignable = std::is_nothrow_copy_assignable<T>::value;template<typename T> concept bool NothrowCopyConstructible = std::is_nothrow_copy_constructible<T>::value;template<typename T> concept bool NothrowDefaultConstructible = std::is_nothrow_default_constructible<T>::value;template<typename T> concept bool NothrowDestructible = std::is_nothrow_destructible<T>::value;template<typename T> concept bool NothrowMoveAssignable = std::is_nothrow_move_assignable<T>::value;template<typename T> concept bool NothrowMoveConstructible = std::is_nothrow_move_constructible<T>::value;template<typename T> concept bool Pod = std::is_pod<T>::value;template<typename T> concept bool Polymorphic = std::is_polymorphic<T>::value;template<typename T> concept bool Signed = std::is_signed<T>::value;template<typename T> concept bool StandardLayout = std::is_standard_layout<T>::value;template<typename T> concept bool Trivial = std::is_trivial<T>::value;template<typename T, typename U> concept bool TriviallyAssignable = std::is_trivially_assignable<T, U>::value;template<typename T> concept bool TriviallyConstructible = std::is_trivially_constructible<T>::value;template<typename T> concept bool TriviallyCopyable = std::is_trivially_copyable<T>::value;template<typename T> concept bool TriviallyCopyAssignable = std::is_trivially_copy_assignable<T>::value;template<typename T> concept bool TriviallyCopyConstructible = std::is_trivially_copy_constructible<T>::value;template<typename T> concept bool TriviallyDefaultConstructible = std::is_trivially_default_constructible<T>::value;template<typename T> concept bool TriviallyDestructible = std::is_trivially_destructible<T>::value;template<typename T> concept bool TriviallyMoveAssignable = std::is_trivially_move_assignable<T>::value;template<typename T> concept bool TriviallyMoveConstructible = std::is_trivially_move_constructible<T>::value;template<typename T> concept bool Unsigned = std::is_unsigned<T>::value;template<typename T> concept bool HasVirtualDestructor = std::has_virtual_destructor<T>::value;template<typename T> concept bool Volatile = std::is_volatile<T>::value;
7.10.2 Property Queries
template<typename T> constexpr auto alignmentOf() -> size_t { return std::alignment_of<T>::value; }template<typename T> constexpr auto extent() -> size_t { return std::extent<T>::value; }template<typename T> constexpr auto rank() -> size_t { return std::rank<T>::value; }constexpr auto alignmentOf(auto &&a) -> size_t { return alignmentOf<decltype(a)>(); }constexpr auto extent(auto &&a) -> size_t { return extent<decltype(a)>(); }constexpr auto rank(auto &&a) -> size_t { return rank<decltype(a)>(); }
7.10.3 Type relationships
template<typename T, typename U> constexpr auto isBaseOf() -> bool { return std::is_base_of<T, U>::value; }template<typename T, typename U> constexpr auto isConvertible() -> bool { return std::is_convertible<T, U>::value; }template<typename T, typename U> constexpr auto isSame() -> bool { return std::is_same<T, U>::value; }constexpr auto isBaseOf(auto &&a, auto &&b) -> bool { return isBaseOf<decltype(a), decltype(b)>(); }constexpr auto isConvertible(auto &&a, auto &&b) -> bool { return isConvertible<decltype(a), decltype(b)>(); }constexpr auto isSame(auto &&a, auto &&b) -> bool { return isSame<decltype(a), decltype(b)>(); }template<typename T, typename U> concept bool BaseOf = std::is_base_of<T, U>::value;template<typename T, typename U> concept bool Convertible = std::is_convertible<T, U>::value;template<typename T, typename U> concept bool Same = std::is_same<T, U>::value;
40 Chapter 7. Documentation
bibi Documentation, Release 0.1
7.10.4 Standard Library Extensions
is_specialization_of / is_variable_specialization_of
template<typename T, template<typename...> typename Base>struct is_specialization_of : public std::false_type {};template<template<typename...> typename Base, typename... Args>struct is_specialization_of<Base<Args...>, Base> : public std::true_type {};
template<typename Var, typename T, template<Var...> typename Base>struct is_variable_specialization_of : public std::false_type {};template<typename Var, template<Var...> typename Base, Var... Args>struct is_variable_specialization_of<Var, Base<Args...>, Base> : public std::true_type {};
template<typename T, template<typename...> typename Base> constexpr bool is_specialization_of_v = is_specialization_of<T, Base>::value;template<typename T, template<typename...> typename Base> constexpr auto isSpecializationOf() -> bool { return is_specialization_of_v<T, Base>; }constexpr auto isSpecializationOf(auto &&t, auto &&base) -> bool { return isSpecializationOf<decltype(t), decltype(base)>(); }
template<typename Var, typename T, template<Var...> typename Base> constexpr bool is_variable_specialization_of_v = is_variable_specialization_of<Var, T, Base>::value;template<typename Var, typename T, template<Var...> typename Base> constexpr auto isVariableSpecializationOf() -> bool { return is_variable_specialization_of_v<Var, T, Base>; }
Example Usage
#include <bibi/TypeTraits.h>#include <chrono>#include <iostream>#include <string>#include <vector>
auto main() -> int{
std::cout << bibi::is_specialization_of<std::vector<int>, std::vector>::value << std::endl;std::cout << bibi::is_specialization_of_v<std::vector<int, std::allocator<int>>, std::vector> << std::endl;std::cout << bibi::isSpecializationOf<std::string, std::vector>() << std::endl;
std::cout << bibi::isVariableSpecializationOf<std::intmax_t, std::chrono::system_clock::period, std::ratio>() << std::endl;std::cout << bibi::is_variable_specialization_of_v<std::intmax_t, std::chrono::steady_clock::period, std::ratio> << std::endl;
}
/*Expected Output:11011
*/
7.10. Type Traits 41
bibi Documentation, Release 0.1
42 Chapter 7. Documentation
CHAPTER 8
License
This library is released under the Boost Software License 1.0.
43