47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
//
|
|
// Created by Patrick Maschek on 22.01.2024.
|
|
//
|
|
|
|
#ifndef CONST_CONTAINER_COMPILEOPTIONAL_H_
|
|
#define CONST_CONTAINER_COMPILEOPTIONAL_H_
|
|
|
|
#include <type_traits>
|
|
#include <initializer_list>
|
|
|
|
namespace cc {
|
|
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;
|
|
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 _value;
|
|
};
|
|
|
|
}
|
|
|
|
#endif //CONST_CONTAINER_COMPILEOPTIONAL_H_
|