const_container/include/CompileOptional.h

32 lines
566 B
C
Raw Normal View History

2024-01-22 22:42:32 +01:00
//
// Created by Patrick Maschek on 22.01.2024.
//
#ifndef CONST_CONTAINER_COMPILEOPTIONAL_H_
#define CONST_CONTAINER_COMPILEOPTIONAL_H_
2024-01-22 23:28:47 +01:00
#include <type_traits>
2024-01-22 22:42:32 +01:00
namespace cc {
2024-01-22 23:28:47 +01:00
template<typename, bool Cond = false>
2024-01-22 22:42:32 +01:00
class CompileOptional {};
2024-01-22 23:28:47 +01:00
template<typename T>
class CompileOptional<T, false> {
public:
using defined = std::false_type;
};
2024-01-22 22:42:32 +01:00
template<typename T>
class CompileOptional<T, true> {
public:
2024-01-22 23:28:47 +01:00
using defined = std::true_type;
2024-01-22 22:42:32 +01:00
operator T&() { return _data; }
2024-01-22 23:28:47 +01:00
private:
T _data;
2024-01-22 22:42:32 +01:00
};
2024-01-22 23:28:47 +01:00
2024-01-22 22:42:32 +01:00
}
2024-01-22 23:28:47 +01:00
#endif //CONST_CONTAINER_COMPILEOPTIONAL_H_