DNA Calib 1.1
Project brief
Common.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6
7#ifdef _MSC_VER
8 #pragma warning(push)
9 #pragma warning(disable : 4365 4987)
10#endif
11#include <tuple>
12#include <type_traits>
13#ifdef _MSC_VER
14 #pragma warning(pop)
15#endif
16
17namespace pma {
18
19class MemoryResource;
20
21} // namespace pma
22
23namespace terse {
24
25namespace impl {
26
27template<typename T>
30 static constexpr bool NeedsMemoryResource = std::is_constructible<T, pma::MemoryResource*>::value;
31 static constexpr bool IsPair = traits::is_pair<T>::value;
32 static constexpr bool IsTuple = traits::is_tuple<T>::value;
33 static constexpr bool IsPrimitive = (!NeedsAllocator && !NeedsMemoryResource & !IsPair & !IsTuple);
34
35 template<class ParentAllocator, bool IsPrimitive = IsPrimitive>
36 static typename std::enable_if<IsPrimitive, T>::type create(const ParentAllocator& /*unused*/) {
37 return T{};
38 }
39
40 template<class ParentAllocator, bool IsPrimitive = IsPrimitive>
41 static typename std::enable_if<!IsPrimitive && NeedsMemoryResource, T>::type create(const ParentAllocator& alloc) {
42 return T{alloc.getMemoryResource()};
43 }
44
45 template<class ParentAllocator, bool IsPrimitive = IsPrimitive>
46 static typename std::enable_if<!IsPrimitive && !NeedsMemoryResource && NeedsAllocator, T>::type create(
47 const ParentAllocator& alloc) {
48 using TAllocator = typename std::allocator_traits<ParentAllocator>::template rebind_alloc<typename T::value_type>;
49 return T{TAllocator{alloc}};
50 }
51
52 template<class ParentAllocator, bool IsPrimitive = IsPrimitive>
53 static typename std::enable_if<!IsPrimitive && !NeedsMemoryResource && !NeedsAllocator && IsPair, T>::type create(
54 const ParentAllocator& alloc) {
55 using K = typename T::first_type;
56 using V = typename T::second_type;
57 return T{ValueFactory<K>::create(alloc), ValueFactory<V>::create(alloc)};
58 }
59
60 template<class ParentAllocator, bool IsPrimitive = IsPrimitive>
61 static typename std::enable_if<!IsPrimitive && !NeedsMemoryResource && !NeedsAllocator && !IsPair && IsTuple, T>::type create(
62 const ParentAllocator& alloc) {
63 using K = typename std::tuple_element<0, T>::type;
64 using V = typename std::tuple_element<0, T>::type;
65 return T{ValueFactory<K>::create(alloc), ValueFactory<V>::create(alloc)};
66 }
67
68};
69
70} // namespace impl
71
72} // namespace terse
Definition: BinaryStreamReader.h:121
Definition: Archive.h:14
Definition: Common.h:28
static constexpr bool NeedsMemoryResource
Definition: Common.h:30
static std::enable_if<!IsPrimitive &&!NeedsMemoryResource &&!NeedsAllocator &&!IsPair &&IsTuple, T >::type create(const ParentAllocator &alloc)
Definition: Common.h:61
static std::enable_if<!IsPrimitive &&!NeedsMemoryResource &&!NeedsAllocator &&IsPair, T >::type create(const ParentAllocator &alloc)
Definition: Common.h:53
static std::enable_if< IsPrimitive, T >::type create(const ParentAllocator &)
Definition: Common.h:36
static std::enable_if<!IsPrimitive &&!NeedsMemoryResource &&NeedsAllocator, T >::type create(const ParentAllocator &alloc)
Definition: Common.h:46
static constexpr bool IsTuple
Definition: Common.h:32
static constexpr bool IsPrimitive
Definition: Common.h:33
static std::enable_if<!IsPrimitive &&NeedsMemoryResource, T >::type create(const ParentAllocator &alloc)
Definition: Common.h:41
static constexpr bool IsPair
Definition: Common.h:31
static constexpr bool NeedsAllocator
Definition: Common.h:29
Definition: Traits.h:122
Definition: Traits.h:128
Definition: Traits.h:28