added ctors and constexpr to CompileOptional
This commit is contained in:
parent
e8fac3a44d
commit
af5c9b2454
|
|
@ -6,24 +6,39 @@
|
|||
#define CONST_CONTAINER_COMPILEOPTIONAL_H_
|
||||
|
||||
#include <type_traits>
|
||||
#include <initializer_list>
|
||||
|
||||
namespace cc {
|
||||
template<typename, bool Cond = false>
|
||||
template<typename T, bool Cond = false>
|
||||
class CompileOptional {};
|
||||
|
||||
template<typename T>
|
||||
class CompileOptional<T, false> {
|
||||
public:
|
||||
using defined = std::false_type;
|
||||
using value_type = T;
|
||||
|
||||
constexpr CompileOptional() = default;
|
||||
constexpr CompileOptional(const value_type& value) {}
|
||||
template<typename ...Args>
|
||||
constexpr CompileOptional(Args... args) {}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class CompileOptional<T, true> {
|
||||
public:
|
||||
using defined = std::true_type;
|
||||
operator T&() { return _data; }
|
||||
using value_type = T;
|
||||
|
||||
constexpr CompileOptional() = default;
|
||||
constexpr CompileOptional(const value_type& value) : _value(value) {}
|
||||
constexpr CompileOptional(value_type&& value) : _value(value) {}
|
||||
template<typename ...Args>
|
||||
constexpr CompileOptional(Args... args) : _value( { std::forward<Args>(args)... } ) {}
|
||||
|
||||
constexpr operator T&() { return _value; }
|
||||
private:
|
||||
T _data;
|
||||
T _value;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue