/* Copyright (C) 2019 Povilas Kanapickas This file is part of cppreference-doc This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. */ #ifndef CPPREFERENCE_VARIANT_H #define CPPREFERENCE_VARIANT_H #if CPPREFERENCE_STDVER >= 2017 #include // exception #include // hash #include // in_place_type_t, ... #include #include namespace std { inline constexpr std::size_t variant_npos = static_cast(-1); struct monostate {}; class bad_variant_access : public exception { public: bad_variant_access(); ~bad_variant_access() override; const char * what() const override; }; template class variant; // forward declaration template struct variant_alternative; // undefined template struct variant_alternative> { using type = CPPREFERENCE_SIMPLIFIED_TYPE; }; template struct variant_alternative> { using type = CPPREFERENCE_SIMPLIFIED_TYPE; }; template struct variant_alternative> { using type = CPPREFERENCE_SIMPLIFIED_TYPE; }; template struct variant_alternative> { using type = CPPREFERENCE_SIMPLIFIED_TYPE; }; template using variant_alternative_t = typename variant_alternative::type; template class variant { public: constexpr variant(); constexpr variant(const variant& other); constexpr variant(variant&& other); template constexpr variant(T&& t); template constexpr explicit variant(in_place_type_t, Args&&... args); template constexpr explicit variant(in_place_type_t, initializer_list il, Args&&... args); template constexpr explicit variant(in_place_index_t, Args&&... args); template constexpr explicit variant(in_place_index_t, initializer_list il, Args&&... args); ~variant(); constexpr variant& operator=(const variant& rhs); constexpr variant& operator=(variant&& rhs); template variant& operator=(T&& t); constexpr size_t index() const; constexpr bool valueless_by_exception() const; template T& emplace(Args&&... args); template T& emplace(initializer_list il, Args&&... args); template variant_alternative_t& emplace(Args&&... args); template variant_alternative_t& emplace(initializer_list il, Args&&... args); void swap(variant& rhs); }; template constexpr bool operator==(const variant& v, const variant& w); template constexpr bool operator!=(const variant& v, const variant& w); template constexpr bool operator<(const variant& v, const variant& w); template constexpr bool operator>(const variant& v, const variant& w); template constexpr bool operator<=(const variant& v, const variant& w); template constexpr bool operator>=(const variant& v, const variant& w); template void swap(variant& lhs, variant& rhs); template constexpr CPPREFERENCE_SIMPLIFIED_TYPE visit(Visitor&& vis, Variants&&... vars); template constexpr R visit(Visitor&&, Variants&&...); template constexpr bool holds_alternative(const variant& v); template constexpr variant_alternative_t>& get(variant& v); template constexpr variant_alternative_t>&& get(variant&& v); template constexpr const variant_alternative_t>& get(const variant& v); template constexpr const variant_alternative_t>& get(const variant&& v); template constexpr T& get(variant& v); template constexpr T&& get(variant&& v); template constexpr const T& get(const variant& v); template constexpr const T&& get(const variant&& v); template constexpr add_pointer_t>> get_if(variant* pv); template constexpr add_pointer_t>> get_if(const variant* pv); template constexpr add_pointer_t get_if(variant* pv); template constexpr add_pointer_t get_if(const variant* pv); template struct variant_size; // undefined template struct variant_size> : integral_constant { }; template struct variant_size> : integral_constant { }; template struct variant_size> : integral_constant { }; template struct variant_size> : integral_constant { }; template struct hash> {}; } // namespace std #endif // CPPREFERENCE_STDVER >= 2017 #endif // CPPREFERENCE_VARIANT_H