#ifndef RFL_FLATTEN_HPP_ #define RFL_FLATTEN_HPP_ #include #include #include #include #include namespace rfl { /// Used to embed another struct into the generated output. template struct Flatten { /// The underlying type. using Type = std::remove_cvref_t; Flatten(const Type& _value) : value_(_value) {} Flatten(Type&& _value) noexcept : value_(std::forward(_value)) {} Flatten(const Flatten& _f) = default; Flatten(Flatten&& _f) noexcept = default; template Flatten(const Flatten& _f) : value_(_f.get()) {} template Flatten(Flatten&& _f) : value_(_f.get()) {} template , bool>::type = true> Flatten(const U& _value) : value_(_value) {} template , bool>::type = true> Flatten(U&& _value) : value_(_value) {} ~Flatten() = default; /// Returns the underlying object. Type& get() { return value_; } /// Returns the underlying object. const Type& get() const { return value_; } /// Returns the underlying object. Type& operator()() { return value_; } /// Returns the underlying object. const Type& operator()() const { return value_; } /// Assigns the underlying object. Flatten& operator=(const T& _value) { value_ = _value; return *this; } /// Assigns the underlying object. Flatten& operator=(T&& _value) { value_ = std::forward(_value); return *this; } /// Assigns the underlying object. template , bool>::type = true> Flatten& operator=(const U& _value) { value_ = _value; return *this; } /// Assigns the underlying object. Flatten& operator=(const Flatten& _f) = default; /// Assigns the underlying object. Flatten& operator=(Flatten&& _f) = default; /// Assigns the underlying object. template Flatten& operator=(const Flatten& _f) { value_ = _f.get(); return *this; } /// Assigns the underlying object. template Flatten& operator=(Flatten&& _f) { value_ = std::forward(_f); return *this; } /// Assigns the underlying object. void set(const Type& _value) { value_ = _value; } /// Assigns the underlying object. void set(Type&& _value) { value_ = std::forward(_value); } /// The underlying value. Type value_; }; } // namespace rfl #endif