mn_ebo_storage.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2018 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 #ifndef __MINILIB_EBCO_EBO_STORAGE_H__
19 #define __MINILIB_EBCO_EBO_STORAGE_H__
20 
21 #include "../mn_config.hpp"
22 
23 #include "../mn_functional.hpp"
24 
25 namespace mn {
26 
27 
28  template <typename T, int TAG = 0, typename = void>
29  class ebo_storage {
30  public:
31  using value_type = T;
32  using reference = T&;
33  using const_reference = const T&;
34 
35  constexpr ebo_storage() = default;
36 
37  template<typename U>
38  constexpr ebo_storage(U&& u) noexcept : m_iItem(mn::forward(u) ) {}
39 
40  reference get() noexcept { return m_iItem; }
41  constexpr const_reference get() const noexcept { return m_iItem; }
42 
43  ebo_storage& operator=( const ebo_storage& other ) = default;
44  ebo_storage& operator=( ebo_storage&& other ) = default;
45  private:
47  };
48 
49  template <typename T, int TAG>
50  class ebo_storage<T, TAG, mn::enable_if_t<mn::is_class<T>::value>> : private T {
51  using base_type = T;
52  public:
53  using value_type = T;
54  using reference = T&;
55  using const_reference = const T&;
56 
57  using base_type::T;
58 
59  constexpr ebo_storage() = default;
61  constexpr ebo_storage(const T&& type) : base_type(mn::move(type)) { }
62 
63  reference get() noexcept { return *this; }
64  constexpr const_reference get() const noexcept { return *this; }
65  };
66 }
67 #endif // __MINILIB_EBCO_EBO_STORAGE_H__
constexpr ebo_storage(const_reference type)
Definition: mn_ebo_storage.hpp:60
const T & const_reference
Definition: mn_ebo_storage.hpp:55
constexpr const_reference get() const noexcept
Definition: mn_ebo_storage.hpp:64
reference get() noexcept
Definition: mn_ebo_storage.hpp:63
constexpr ebo_storage(const T &&type)
Definition: mn_ebo_storage.hpp:61
Definition: mn_ebo_storage.hpp:29
T & reference
Definition: mn_ebo_storage.hpp:32
constexpr ebo_storage()=default
const T & const_reference
Definition: mn_ebo_storage.hpp:33
T value_type
Definition: mn_ebo_storage.hpp:31
reference get() noexcept
Definition: mn_ebo_storage.hpp:40
constexpr const_reference get() const noexcept
Definition: mn_ebo_storage.hpp:41
ebo_storage & operator=(const ebo_storage &other)=default
constexpr ebo_storage(U &&u) noexcept
Definition: mn_ebo_storage.hpp:38
T m_iItem
Definition: mn_ebo_storage.hpp:46
ebo_storage & operator=(ebo_storage &&other)=default
#define TAG
Definition: mn_system_esp32.cpp:39
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
struct mn::memory::detail::ptr_difference type
Definition: mn_allocator_typetraits.hpp:25
type_t< enable_if< b, T > > enable_if_t
Definition: mn_functional.hpp:194
void move(const T *src, const T *last, T *dest)
Definition: mn_algorithm.hpp:100
T && forward(remove_reference_t< T > &t)
Definition: mn_functional.hpp:74