Index: vendor/libc++/dist/docs/conf.py =================================================================== --- vendor/libc++/dist/docs/conf.py (revision 313637) +++ vendor/libc++/dist/docs/conf.py (revision 313638) @@ -1,251 +1,251 @@ # -*- coding: utf-8 -*- # # libc++ documentation build configuration file. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys, os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.intersphinx', 'sphinx.ext.todo'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'libc++' copyright = u'2011-2017, LLVM Project' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '4.0' +version = '4' # The full version, including alpha/beta/rc tags. -release = '4.0' +release = '4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. today_fmt = '%Y-%m-%d' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. show_authors = True # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'friendly' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'haiku' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'libcxxdoc' # -- Options for LaTeX output -------------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('contents', 'libcxx.tex', u'libcxx Documentation', u'LLVM project', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('contents', 'libc++', u'libc++ Documentation', [u'LLVM project'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('contents', 'libc++', u'libc++ Documentation', u'LLVM project', 'libc++', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # FIXME: Define intersphinx configration. intersphinx_mapping = {} # -- Options for extensions ---------------------------------------------------- # Enable this if you want TODOs to show up in the generated documentation. todo_include_todos = True Index: vendor/libc++/dist/include/optional =================================================================== --- vendor/libc++/dist/include/optional (revision 313637) +++ vendor/libc++/dist/include/optional (revision 313638) @@ -1,1314 +1,1312 @@ // -*- C++ -*- //===-------------------------- optional ----------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_OPTIONAL #define _LIBCPP_OPTIONAL /* optional synopsis // C++1z namespace std { // 20.6.3, optional for object types template class optional; // 20.6.4, no-value state indicator struct nullopt_t{see below }; constexpr nullopt_t nullopt(unspecified ); // 20.6.5, class bad_optional_access class bad_optional_access; // 20.6.6, relational operators template constexpr bool operator==(const optional&, const optional&); template constexpr bool operator!=(const optional&, const optional&); template constexpr bool operator<(const optional&, const optional&); template constexpr bool operator>(const optional&, const optional&); template constexpr bool operator<=(const optional&, const optional&); template constexpr bool operator>=(const optional&, const optional&); template constexpr bool operator==(const optional&, nullopt_t) noexcept; template constexpr bool operator==(nullopt_t, const optional&) noexcept; template constexpr bool operator!=(const optional&, nullopt_t) noexcept; template constexpr bool operator!=(nullopt_t, const optional&) noexcept; template constexpr bool operator<(const optional&, nullopt_t) noexcept; template constexpr bool operator<(nullopt_t, const optional&) noexcept; template constexpr bool operator<=(const optional&, nullopt_t) noexcept; template constexpr bool operator<=(nullopt_t, const optional&) noexcept; template constexpr bool operator>(const optional&, nullopt_t) noexcept; template constexpr bool operator>(nullopt_t, const optional&) noexcept; template constexpr bool operator>=(const optional&, nullopt_t) noexcept; template constexpr bool operator>=(nullopt_t, const optional&) noexcept; // 20.6.8, comparison with T template constexpr bool operator==(const optional&, const T&); template constexpr bool operator==(const T&, const optional&); template constexpr bool operator!=(const optional&, const T&); template constexpr bool operator!=(const T&, const optional&); template constexpr bool operator<(const optional&, const T&); template constexpr bool operator<(const T&, const optional&); template constexpr bool operator<=(const optional&, const T&); template constexpr bool operator<=(const T&, const optional&); template constexpr bool operator>(const optional&, const T&); template constexpr bool operator>(const T&, const optional&); template constexpr bool operator>=(const optional&, const T&); template constexpr bool operator>=(const T&, const optional&); // 20.6.9, specialized algorithms template void swap(optional&, optional&) noexcept(see below ); template constexpr optional make_optional(T&&); template constexpr optional make_optional(Args&&... args); template constexpr optional make_optional(initializer_list il, Args&&... args); // 20.6.10, hash support template struct hash; template struct hash>; template class optional { public: using value_type = T; // 20.6.3.1, constructors constexpr optional() noexcept; constexpr optional(nullopt_t) noexcept; optional(const optional &); optional(optional &&) noexcept(see below ); template constexpr explicit optional(in_place_t, Args &&...); template constexpr explicit optional(in_place_t, initializer_list, Args &&...); template constexpr EXPLICIT optional(U &&); template constexpr EXPLICIT optional(const optional &); template constexpr EXPLICIT optional(optional &&); // 20.6.3.2, destructor ~optional(); // 20.6.3.3, assignment optional &operator=(nullopt_t) noexcept; optional &operator=(const optional &); optional &operator=(optional &&) noexcept(see below ); template optional &operator=(U &&); template optional &operator=(const optional &); template optional &operator=(optional &&); template void emplace(Args &&...); template void emplace(initializer_list, Args &&...); // 20.6.3.4, swap void swap(optional &) noexcept(see below ); // 20.6.3.5, observers constexpr T const *operator->() const; constexpr T *operator->(); constexpr T const &operator*() const &; constexpr T &operator*() &; constexpr T &&operator*() &&; constexpr const T &&operator*() const &&; constexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept; constexpr T const &value() const &; constexpr T &value() &; constexpr T &&value() &&; constexpr const T &&value() const &&; template constexpr T value_or(U &&) const &; template constexpr T value_or(U &&) &&; // 20.6.3.6, modifiers void reset() noexcept; private: T *val; // exposition only }; } // namespace std */ #include <__config> #include <__debug> #include <__functional_base> #include <__undef_min_max> #include #include #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif namespace std // purposefully not using versioning namespace { class _LIBCPP_EXCEPTION_ABI bad_optional_access - : public logic_error + : public exception { public: - _LIBCPP_INLINE_VISIBILITY - bad_optional_access() : logic_error("bad optional access") {} - // Get the key function ~bad_optional_access() into the dylib virtual ~bad_optional_access() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; }; } // std #if _LIBCPP_STD_VER > 14 _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY void __throw_bad_optional_access() { #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_optional_access(); #else _VSTD::abort(); #endif } struct nullopt_t { struct __secret_tag { _LIBCPP_INLINE_VISIBILITY explicit __secret_tag() = default; }; _LIBCPP_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {} }; /* inline */ constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}}; template ::value> struct __optional_destruct_base; template struct __optional_destruct_base<_Tp, false> { typedef _Tp value_type; static_assert(is_object_v, "instantiation of optional with a non-object type is undefined behavior"); union { char __null_state_; value_type __val_; }; bool __engaged_; _LIBCPP_INLINE_VISIBILITY ~__optional_destruct_base() { if (__engaged_) __val_.~value_type(); } _LIBCPP_INLINE_VISIBILITY constexpr __optional_destruct_base() noexcept : __null_state_(), __engaged_(false) {} template _LIBCPP_INLINE_VISIBILITY constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) : __val_(_VSTD::forward<_Args>(__args)...), __engaged_(true) {} _LIBCPP_INLINE_VISIBILITY void reset() noexcept { if (__engaged_) { __val_.~value_type(); __engaged_ = false; } } }; template struct __optional_destruct_base<_Tp, true> { typedef _Tp value_type; static_assert(is_object_v, "instantiation of optional with a non-object type is undefined behavior"); union { char __null_state_; value_type __val_; }; bool __engaged_; _LIBCPP_INLINE_VISIBILITY constexpr __optional_destruct_base() noexcept : __null_state_(), __engaged_(false) {} template _LIBCPP_INLINE_VISIBILITY constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) : __val_(_VSTD::forward<_Args>(__args)...), __engaged_(true) {} _LIBCPP_INLINE_VISIBILITY void reset() noexcept { if (__engaged_) { __engaged_ = false; } } }; template ::value> struct __optional_storage_base : __optional_destruct_base<_Tp> { using __base = __optional_destruct_base<_Tp>; using value_type = _Tp; using __base::__base; _LIBCPP_INLINE_VISIBILITY constexpr bool has_value() const noexcept { return this->__engaged_; } _LIBCPP_INLINE_VISIBILITY constexpr value_type& __get() & noexcept { return this->__val_; } _LIBCPP_INLINE_VISIBILITY constexpr const value_type& __get() const& noexcept { return this->__val_; } _LIBCPP_INLINE_VISIBILITY constexpr value_type&& __get() && noexcept { return _VSTD::move(this->__val_); } _LIBCPP_INLINE_VISIBILITY constexpr const value_type&& __get() const&& noexcept { return _VSTD::move(this->__val_); } template _LIBCPP_INLINE_VISIBILITY void __construct(_Args&&... __args) { _LIBCPP_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); ::new((void*)_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Args>(__args)...); this->__engaged_ = true; } template _LIBCPP_INLINE_VISIBILITY void __construct_from(_That&& __opt) { if (__opt.has_value()) __construct(_VSTD::forward<_That>(__opt).__get()); } template _LIBCPP_INLINE_VISIBILITY void __assign_from(_That&& __opt) { if (this->__engaged_ == __opt.has_value()) { if (this->__engaged_) this->__val_ = _VSTD::forward<_That>(__opt).__get(); } else { if (this->__engaged_) this->reset(); else __construct(_VSTD::forward<_That>(__opt).__get()); } } }; // optional is currently required ill-formed, however it may to be in the // future. For this reason it has already been implemented to ensure we can // make the change in an ABI compatible manner. template struct __optional_storage_base<_Tp, true> { using value_type = _Tp; using __raw_type = remove_reference_t<_Tp>; __raw_type* __value_; template static constexpr bool __can_bind_reference() { using _RawUp = typename remove_reference<_Up>::type; using _UpPtr = _RawUp*; using _RawTp = typename remove_reference<_Tp>::type; using _TpPtr = _RawTp*; using _CheckLValueArg = integral_constant::value && is_convertible<_UpPtr, _TpPtr>::value) || is_same<_RawUp, reference_wrapper<_RawTp>>::value || is_same<_RawUp, reference_wrapper::type>>::value >; return (is_lvalue_reference<_Tp>::value && _CheckLValueArg::value) || (is_rvalue_reference<_Tp>::value && !is_lvalue_reference<_Up>::value && is_convertible<_UpPtr, _TpPtr>::value); } _LIBCPP_INLINE_VISIBILITY constexpr __optional_storage_base() noexcept : __value_(nullptr) {} template _LIBCPP_INLINE_VISIBILITY constexpr explicit __optional_storage_base(in_place_t, _UArg&& __uarg) : __value_(_VSTD::addressof(__uarg)) { static_assert(__can_bind_reference<_UArg>(), "Attempted to construct a reference element in tuple from a " "possible temporary"); } _LIBCPP_INLINE_VISIBILITY void reset() noexcept { __value_ = nullptr; } _LIBCPP_INLINE_VISIBILITY constexpr bool has_value() const noexcept { return __value_ != nullptr; } _LIBCPP_INLINE_VISIBILITY constexpr value_type& __get() const& noexcept { return *__value_; } _LIBCPP_INLINE_VISIBILITY constexpr value_type&& __get() const&& noexcept { return _VSTD::forward(*__value_); } template _LIBCPP_INLINE_VISIBILITY void __construct(_UArg&& __val) { _LIBCPP_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); static_assert(__can_bind_reference<_UArg>(), "Attempted to construct a reference element in tuple from a " "possible temporary"); __value_ = _VSTD::addressof(__val); } template _LIBCPP_INLINE_VISIBILITY void __construct_from(_That&& __opt) { if (__opt.has_value()) __construct(_VSTD::forward<_That>(__opt).__get()); } template _LIBCPP_INLINE_VISIBILITY void __assign_from(_That&& __opt) { if (has_value() == __opt.has_value()) { if (has_value()) *__value_ = _VSTD::forward<_That>(__opt).__get(); } else { if (has_value()) reset(); else __construct(_VSTD::forward<_That>(__opt).__get()); } } }; template ::value> struct __optional_storage; template struct __optional_storage<_Tp, true> : __optional_storage_base<_Tp> { using __optional_storage_base<_Tp>::__optional_storage_base; }; template struct __optional_storage<_Tp, false> : __optional_storage_base<_Tp> { using value_type = _Tp; using __optional_storage_base<_Tp>::__optional_storage_base; _LIBCPP_INLINE_VISIBILITY __optional_storage() = default; _LIBCPP_INLINE_VISIBILITY __optional_storage(const __optional_storage& __opt) { this->__construct_from(__opt); } _LIBCPP_INLINE_VISIBILITY __optional_storage(__optional_storage&& __opt) noexcept(is_nothrow_move_constructible_v) { this->__construct_from(_VSTD::move(__opt)); } _LIBCPP_INLINE_VISIBILITY __optional_storage& operator=(const __optional_storage& __opt) { this->__assign_from(__opt); return *this; } _LIBCPP_INLINE_VISIBILITY __optional_storage& operator=(__optional_storage&& __opt) noexcept(is_nothrow_move_assignable_v && is_nothrow_move_constructible_v) { this->__assign_from(_VSTD::move(__opt)); return *this; } }; template using __optional_sfinae_ctor_base_t = __sfinae_ctor_base< is_copy_constructible<_Tp>::value, is_move_constructible<_Tp>::value >; template using __optional_sfinae_assign_base_t = __sfinae_assign_base< (is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value), (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value) >; template class optional : private __optional_storage<_Tp> , private __optional_sfinae_ctor_base_t<_Tp> , private __optional_sfinae_assign_base_t<_Tp> { using __base = __optional_storage<_Tp>; public: using value_type = _Tp; private: // Disable the reference extension using this static assert. static_assert(!is_same_v, "instantiation of optional with in_place_t is ill-formed"); static_assert(!is_same_v<__uncvref_t, nullopt_t>, "instantiation of optional with nullopt_t is ill-formed"); static_assert(!is_reference_v, "instantiation of optional with a reference type is ill-formed"); static_assert(is_destructible_v, "instantiation of optional with a non-destructible type is ill-formed"); // LWG2756: conditionally explicit conversion from _Up struct _CheckOptionalArgsConstructor { template static constexpr bool __enable_implicit() { return is_constructible_v<_Tp, _Up&&> && is_convertible_v<_Up&&, _Tp>; } template static constexpr bool __enable_explicit() { return is_constructible_v<_Tp, _Up&&> && !is_convertible_v<_Up&&, _Tp>; } }; template using _CheckOptionalArgsCtor = conditional_t< !is_same_v && !is_same_v, optional>, _CheckOptionalArgsConstructor, __check_tuple_constructor_fail >; template struct _CheckOptionalLikeConstructor { template > using __check_constructible_from_opt = __lazy_or< is_constructible<_Tp, _Opt&>, is_constructible<_Tp, _Opt const&>, is_constructible<_Tp, _Opt&&>, is_constructible<_Tp, _Opt const&&>, is_convertible<_Opt&, _Tp>, is_convertible<_Opt const&, _Tp>, is_convertible<_Opt&&, _Tp>, is_convertible<_Opt const&&, _Tp> >; template > using __check_assignable_from_opt = __lazy_or< is_assignable<_Tp&, _Opt&>, is_assignable<_Tp&, _Opt const&>, is_assignable<_Tp&, _Opt&&>, is_assignable<_Tp&, _Opt const&&> >; template static constexpr bool __enable_implicit() { return is_convertible<_QUp, _Tp>::value && !__check_constructible_from_opt<_Up>::value; } template static constexpr bool __enable_explicit() { return !is_convertible<_QUp, _Tp>::value && !__check_constructible_from_opt<_Up>::value; } template static constexpr bool __enable_assign() { // Construction and assignability of _Qup to _Tp has already been // checked. return !__check_constructible_from_opt<_Up>::value && !__check_assignable_from_opt<_Up>::value; } }; template using _CheckOptionalLikeCtor = conditional_t< __lazy_and< __lazy_not>, is_constructible<_Tp, _QualUp> >::value, _CheckOptionalLikeConstructor<_QualUp>, __check_tuple_constructor_fail >; template using _CheckOptionalLikeAssign = conditional_t< __lazy_and< __lazy_not>, is_constructible<_Tp, _QualUp>, is_assignable<_Tp&, _QualUp> >::value, _CheckOptionalLikeConstructor<_QualUp>, __check_tuple_constructor_fail >; public: _LIBCPP_INLINE_VISIBILITY constexpr optional() noexcept {} _LIBCPP_INLINE_VISIBILITY optional(const optional&) = default; _LIBCPP_INLINE_VISIBILITY optional(optional&&) = default; _LIBCPP_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {} template > > _LIBCPP_INLINE_VISIBILITY constexpr explicit optional(in_place_t, _Args&&... __args) : __base(in_place, _VSTD::forward<_Args>(__args)...) {} template &, _Args...>> > _LIBCPP_INLINE_VISIBILITY constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) : __base(in_place, __il, _VSTD::forward<_Args>(__args)...) {} template ::template __enable_implicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY constexpr optional(_Up&& __v) : __base(in_place, _VSTD::forward<_Up>(__v)) {} template ::template __enable_explicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY constexpr explicit optional(_Up&& __v) : __base(in_place, _VSTD::forward<_Up>(__v)) {} // LWG2756: conditionally explicit conversion from const optional<_Up>& template ::template __enable_implicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY optional(const optional<_Up>& __v) { this->__construct_from(__v); } template ::template __enable_explicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY explicit optional(const optional<_Up>& __v) { this->__construct_from(__v); } // LWG2756: conditionally explicit conversion from optional<_Up>&& template ::template __enable_implicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY optional(optional<_Up>&& __v) { this->__construct_from(_VSTD::move(__v)); } template ::template __enable_explicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY explicit optional(optional<_Up>&& __v) { this->__construct_from(_VSTD::move(__v)); } _LIBCPP_INLINE_VISIBILITY optional& operator=(nullopt_t) noexcept { reset(); return *this; } _LIBCPP_INLINE_VISIBILITY optional& operator=(const optional&) = default; _LIBCPP_INLINE_VISIBILITY optional& operator=(optional&&) = default; // LWG2756 template , optional> && !(is_same_v<_Up, value_type> && is_scalar_v) >, is_constructible, is_assignable >::value> > _LIBCPP_INLINE_VISIBILITY optional& operator=(_Up&& __v) { if (this->has_value()) this->__get() = _VSTD::forward<_Up>(__v); else this->__construct(_VSTD::forward<_Up>(__v)); return *this; } // LWG2756 template ::template __enable_assign<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY optional& operator=(const optional<_Up>& __v) { this->__assign_from(__v); return *this; } // LWG2756 template ::template __enable_assign<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY optional& operator=(optional<_Up>&& __v) { this->__assign_from(_VSTD::move(__v)); return *this; } template > > _LIBCPP_INLINE_VISIBILITY void emplace(_Args&&... __args) { reset(); this->__construct(_VSTD::forward<_Args>(__args)...); } template &, _Args...> > > _LIBCPP_INLINE_VISIBILITY void emplace(initializer_list<_Up> __il, _Args&&... __args) { reset(); this->__construct(__il, _VSTD::forward<_Args>(__args)...); } _LIBCPP_INLINE_VISIBILITY void swap(optional& __opt) noexcept(is_nothrow_move_constructible_v && is_nothrow_swappable_v) { if (this->has_value() == __opt.has_value()) { using _VSTD::swap; if (this->has_value()) swap(this->__get(), __opt.__get()); } else { if (this->has_value()) { __opt.__construct(_VSTD::move(this->__get())); reset(); } else { this->__construct(_VSTD::move(__opt.__get())); __opt.reset(); } } } _LIBCPP_INLINE_VISIBILITY constexpr add_pointer_t operator->() const { _LIBCPP_ASSERT(this->has_value(), "optional operator-> called for disengaged value"); #ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF return _VSTD::addressof(this->__get()); #else return __operator_arrow(__has_operator_addressof{}, this->__get()); #endif } _LIBCPP_INLINE_VISIBILITY constexpr add_pointer_t operator->() { _LIBCPP_ASSERT(this->has_value(), "optional operator-> called for disengaged value"); #ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF return _VSTD::addressof(this->__get()); #else return __operator_arrow(__has_operator_addressof{}, this->__get()); #endif } _LIBCPP_INLINE_VISIBILITY constexpr const value_type& operator*() const& { _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); return this->__get(); } _LIBCPP_INLINE_VISIBILITY constexpr value_type& operator*() & { _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); return this->__get(); } _LIBCPP_INLINE_VISIBILITY constexpr value_type&& operator*() && { _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); return _VSTD::move(this->__get()); } _LIBCPP_INLINE_VISIBILITY constexpr const value_type&& operator*() const&& { _LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value"); return _VSTD::move(this->__get()); } _LIBCPP_INLINE_VISIBILITY constexpr explicit operator bool() const noexcept { return has_value(); } using __base::has_value; using __base::__get; _LIBCPP_INLINE_VISIBILITY constexpr value_type const& value() const& { if (!this->has_value()) __throw_bad_optional_access(); return this->__get(); } _LIBCPP_INLINE_VISIBILITY constexpr value_type& value() & { if (!this->has_value()) __throw_bad_optional_access(); return this->__get(); } _LIBCPP_INLINE_VISIBILITY constexpr value_type&& value() && { if (!this->has_value()) __throw_bad_optional_access(); return _VSTD::move(this->__get()); } _LIBCPP_INLINE_VISIBILITY constexpr value_type const&& value() const&& { if (!this->has_value()) __throw_bad_optional_access(); return _VSTD::move(this->__get()); } template _LIBCPP_INLINE_VISIBILITY constexpr value_type value_or(_Up&& __v) const& { static_assert(is_copy_constructible_v, "optional::value_or: T must be copy constructible"); static_assert(is_convertible_v<_Up, value_type>, "optional::value_or: U must be convertible to T"); return this->has_value() ? this->__get() : static_cast(_VSTD::forward<_Up>(__v)); } template _LIBCPP_INLINE_VISIBILITY value_type value_or(_Up&& __v) && { static_assert(is_move_constructible_v, "optional::value_or: T must be move constructible"); static_assert(is_convertible_v<_Up, value_type>, "optional::value_or: U must be convertible to T"); return this->has_value() ? _VSTD::move(this->__get()) : static_cast(_VSTD::forward<_Up>(__v)); } using __base::reset; private: template _LIBCPP_INLINE_VISIBILITY static _Up* __operator_arrow(true_type, _Up& __x) { return _VSTD::addressof(__x); } template _LIBCPP_INLINE_VISIBILITY static constexpr _Up* __operator_arrow(false_type, _Up& __x) { return &__x; } }; // Comparisons between optionals template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() == _VSTD::declval()), bool>, bool > operator==(const optional<_Tp>& __x, const optional<_Tp>& __y) { if (static_cast(__x) != static_cast(__y)) return false; if (!static_cast(__x)) return true; return *__x == *__y; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() != _VSTD::declval()), bool>, bool > operator!=(const optional<_Tp>& __x, const optional<_Tp>& __y) { if (static_cast(__x) != static_cast(__y)) return true; if (!static_cast(__x)) return false; return *__x != *__y; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() < _VSTD::declval()), bool>, bool > operator<(const optional<_Tp>& __x, const optional<_Tp>& __y) { if (!static_cast(__y)) return false; if (!static_cast(__x)) return true; return *__x < *__y; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() > _VSTD::declval()), bool>, bool > operator>(const optional<_Tp>& __x, const optional<_Tp>& __y) { if (!static_cast(__x)) return false; if (!static_cast(__y)) return true; return *__x > *__y; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() <= _VSTD::declval()), bool>, bool > operator<=(const optional<_Tp>& __x, const optional<_Tp>& __y) { if (!static_cast(__x)) return true; if (!static_cast(__y)) return false; return *__x <= *__y; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() >= _VSTD::declval()), bool>, bool > operator>=(const optional<_Tp>& __x, const optional<_Tp>& __y) { if (!static_cast(__y)) return true; if (!static_cast(__x)) return false; return *__x >= *__y; } // Comparisons with nullopt template _LIBCPP_INLINE_VISIBILITY constexpr bool operator==(const optional<_Tp>& __x, nullopt_t) noexcept { return !static_cast(__x); } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator==(nullopt_t, const optional<_Tp>& __x) noexcept { return !static_cast(__x); } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator!=(const optional<_Tp>& __x, nullopt_t) noexcept { return static_cast(__x); } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator!=(nullopt_t, const optional<_Tp>& __x) noexcept { return static_cast(__x); } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator<(const optional<_Tp>&, nullopt_t) noexcept { return false; } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator<(nullopt_t, const optional<_Tp>& __x) noexcept { return static_cast(__x); } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator<=(const optional<_Tp>& __x, nullopt_t) noexcept { return !static_cast(__x); } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator<=(nullopt_t, const optional<_Tp>&) noexcept { return true; } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator>(const optional<_Tp>& __x, nullopt_t) noexcept { return static_cast(__x); } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator>(nullopt_t, const optional<_Tp>&) noexcept { return false; } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator>=(const optional<_Tp>&, nullopt_t) noexcept { return true; } template _LIBCPP_INLINE_VISIBILITY constexpr bool operator>=(nullopt_t, const optional<_Tp>& __x) noexcept { return !static_cast(__x); } // Comparisons with T template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() == _VSTD::declval()), bool>, bool > operator==(const optional<_Tp>& __x, const _Tp& __v) { return static_cast(__x) ? *__x == __v : false; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() == _VSTD::declval()), bool>, bool > operator==(const _Tp& __v, const optional<_Tp>& __x) { return static_cast(__x) ? __v == *__x : false; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() != _VSTD::declval()), bool>, bool > operator!=(const optional<_Tp>& __x, const _Tp& __v) { return static_cast(__x) ? *__x != __v : true; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() != _VSTD::declval()), bool>, bool > operator!=(const _Tp& __v, const optional<_Tp>& __x) { return static_cast(__x) ? __v != *__x : true; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() < _VSTD::declval()), bool>, bool > operator<(const optional<_Tp>& __x, const _Tp& __v) { return static_cast(__x) ? *__x < __v : true; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() < _VSTD::declval()), bool>, bool > operator<(const _Tp& __v, const optional<_Tp>& __x) { return static_cast(__x) ? __v < *__x : false; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() <= _VSTD::declval()), bool>, bool > operator<=(const optional<_Tp>& __x, const _Tp& __v) { return static_cast(__x) ? *__x <= __v : true; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() <= _VSTD::declval()), bool>, bool > operator<=(const _Tp& __v, const optional<_Tp>& __x) { return static_cast(__x) ? __v <= *__x : false; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() > _VSTD::declval()), bool>, bool > operator>(const optional<_Tp>& __x, const _Tp& __v) { return static_cast(__x) ? *__x > __v : false; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() > _VSTD::declval()), bool>, bool > operator>(const _Tp& __v, const optional<_Tp>& __x) { return static_cast(__x) ? __v > *__x : true; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() >= _VSTD::declval()), bool>, bool > operator>=(const optional<_Tp>& __x, const _Tp& __v) { return static_cast(__x) ? *__x >= __v : false; } template _LIBCPP_INLINE_VISIBILITY constexpr enable_if_t< is_convertible_v() >= _VSTD::declval()), bool>, bool > operator>=(const _Tp& __v, const optional<_Tp>& __x) { return static_cast(__x) ? __v >= *__x : true; } template inline _LIBCPP_INLINE_VISIBILITY enable_if_t< is_move_constructible_v<_Tp> && is_swappable_v<_Tp>, void > swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) { __x.swap(__y); } template _LIBCPP_INLINE_VISIBILITY constexpr optional> make_optional(_Tp&& __v) { return optional>(_VSTD::forward<_Tp>(__v)); } template _LIBCPP_INLINE_VISIBILITY constexpr optional<_Tp> make_optional(_Args&&... __args) { return optional<_Tp>(in_place, _VSTD::forward<_Args>(__args)...); } template _LIBCPP_INLINE_VISIBILITY constexpr optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... __args) { return optional<_Tp>(in_place, __il, _VSTD::forward<_Args>(__args)...); } template struct _LIBCPP_TEMPLATE_VIS hash > { typedef optional<_Tp> argument_type; typedef size_t result_type; _LIBCPP_INLINE_VISIBILITY result_type operator()(const argument_type& __opt) const _NOEXCEPT { return static_cast(__opt) ? hash<_Tp>()(*__opt) : 0; } }; _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STD_VER > 14 #endif // _LIBCPP_OPTIONAL Index: vendor/libc++/dist/include/variant =================================================================== --- vendor/libc++/dist/include/variant (revision 313637) +++ vendor/libc++/dist/include/variant (revision 313638) @@ -1,1568 +1,1568 @@ // -*- C++ -*- //===------------------------------ variant -------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_VARIANT #define _LIBCPP_VARIANT /* variant synopsis namespace std { // 20.7.2, class template variant template class variant { public: // 20.7.2.1, constructors constexpr variant() noexcept(see below); variant(const variant&); variant(variant&&) noexcept(see below); template constexpr variant(T&&) noexcept(see below); template constexpr explicit variant(in_place_type_t, Args&&...); template constexpr explicit variant( in_place_type_t, initializer_list, Args&&...); template constexpr explicit variant(in_place_index_t, Args&&...); template constexpr explicit variant( in_place_index_t, initializer_list, Args&&...); // 20.7.2.2, destructor ~variant(); // 20.7.2.3, assignment variant& operator=(const variant&); variant& operator=(variant&&) noexcept(see below); template variant& operator=(T&&) noexcept(see below); // 20.7.2.4, modifiers template void emplace(Args&&...); template void emplace(initializer_list, Args&&...); template void emplace(Args&&...); template void emplace(initializer_list, Args&&...); // 20.7.2.5, value status constexpr bool valueless_by_exception() const noexcept; constexpr size_t index() const noexcept; // 20.7.2.6, swap void swap(variant&) noexcept(see below); }; // 20.7.3, variant helper classes template struct variant_size; // undefined template constexpr size_t variant_size_v = variant_size::value; template struct variant_size; template struct variant_size; template struct variant_size; template struct variant_size>; template struct variant_alternative; // undefined template using variant_alternative_t = typename variant_alternative::type; template struct variant_alternative; template struct variant_alternative; template struct variant_alternative; template struct variant_alternative>; constexpr size_t variant_npos = -1; // 20.7.4, value access template constexpr bool holds_alternative(const variant&) noexcept; template constexpr variant_alternative_t>& get(variant&); template constexpr variant_alternative_t>&& get(variant&&); template constexpr variant_alternative_t> const& get(const variant&); template constexpr variant_alternative_t> const&& get(const variant&&); template constexpr T& get(variant&); template constexpr T&& get(variant&&); template constexpr const T& get(const variant&); template constexpr const T&& get(const variant&&); template constexpr add_pointer_t>> get_if(variant*) noexcept; template constexpr add_pointer_t>> get_if(const variant*) noexcept; template constexpr add_pointer_t get_if(variant*) noexcept; template constexpr add_pointer_t get_if(const variant*) noexcept; // 20.7.5, relational operators template constexpr bool operator==(const variant&, const variant&); template constexpr bool operator!=(const variant&, const variant&); template constexpr bool operator<(const variant&, const variant&); template constexpr bool operator>(const variant&, const variant&); template constexpr bool operator<=(const variant&, const variant&); template constexpr bool operator>=(const variant&, const variant&); // 20.7.6, visitation template constexpr see below visit(Visitor&&, Variants&&...); // 20.7.7, class monostate struct monostate; // 20.7.8, monostate relational operators constexpr bool operator<(monostate, monostate) noexcept; constexpr bool operator>(monostate, monostate) noexcept; constexpr bool operator<=(monostate, monostate) noexcept; constexpr bool operator>=(monostate, monostate) noexcept; constexpr bool operator==(monostate, monostate) noexcept; constexpr bool operator!=(monostate, monostate) noexcept; // 20.7.9, specialized algorithms template void swap(variant&, variant&) noexcept(see below); // 20.7.10, class bad_variant_access class bad_variant_access; // 20.7.11, hash support template struct hash; template struct hash>; template <> struct hash; } // namespace std */ #include <__config> #include <__tuple> #include #include #include #include #include #include #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif namespace std { // explicitly not using versioning namespace class _LIBCPP_EXCEPTION_ABI bad_variant_access : public exception { public: virtual const char* what() const _NOEXCEPT; }; } // namespace std _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY void __throw_bad_variant_access() { #ifndef _LIBCPP_NO_EXCEPTIONS throw bad_variant_access(); #else _VSTD::abort(); #endif } template class _LIBCPP_TEMPLATE_VIS variant; template struct _LIBCPP_TEMPLATE_VIS variant_size; template constexpr size_t variant_size_v = variant_size<_Tp>::value; template struct _LIBCPP_TEMPLATE_VIS variant_size : variant_size<_Tp> {}; template struct _LIBCPP_TEMPLATE_VIS variant_size : variant_size<_Tp> {}; template struct _LIBCPP_TEMPLATE_VIS variant_size : variant_size<_Tp> {}; template struct _LIBCPP_TEMPLATE_VIS variant_size> : integral_constant {}; template struct _LIBCPP_TEMPLATE_VIS variant_alternative; template using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type; template struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const _Tp> : add_const> {}; template struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, volatile _Tp> : add_volatile> {}; template struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp> : add_cv> {}; template struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> { static_assert(_Ip < sizeof...(_Types)); using type = __type_pack_element<_Ip, _Types...>; }; constexpr size_t variant_npos = static_cast(-1); constexpr unsigned int __variant_npos = static_cast(-1); namespace __find_detail { template inline _LIBCPP_INLINE_VISIBILITY constexpr size_t __find_index() { constexpr bool __matches[] = {is_same_v<_Tp, _Types>...}; size_t __result = __not_found; for (size_t __i = 0; __i < sizeof...(_Types); ++__i) { if (__matches[__i]) { if (__result != __not_found) { return __ambiguous; } __result = __i; } } return __result; } template struct __find_unambiguous_index_sfinae_impl : integral_constant {}; template <> struct __find_unambiguous_index_sfinae_impl<__not_found> {}; template <> struct __find_unambiguous_index_sfinae_impl<__ambiguous> {}; template struct __find_unambiguous_index_sfinae : __find_unambiguous_index_sfinae_impl<__find_index<_Tp, _Types...>()> {}; } // namespace __find_detail namespace __variant_detail { struct __valueless_t {}; enum class _Trait { _TriviallyAvailable, _Available, _Unavailable }; template class _IsTriviallyAvailable, template class _IsAvailable> constexpr _Trait __trait = _IsTriviallyAvailable<_Tp>::value ? _Trait::_TriviallyAvailable : _IsAvailable<_Tp>::value ? _Trait::_Available : _Trait::_Unavailable; inline _LIBCPP_INLINE_VISIBILITY constexpr _Trait __common_trait(initializer_list<_Trait> __traits) { _Trait __result = _Trait::_TriviallyAvailable; for (_Trait __t : __traits) { if (static_cast(__t) > static_cast(__result)) { __result = __t; } } return __result; } template struct __traits { static constexpr _Trait __copy_constructible_trait = __common_trait({__trait<_Types, is_trivially_copy_constructible, is_copy_constructible>...}); static constexpr _Trait __move_constructible_trait = __common_trait({__trait<_Types, is_trivially_move_constructible, is_move_constructible>...}); static constexpr _Trait __copy_assignable_trait = __common_trait( {__copy_constructible_trait, __move_constructible_trait, __trait<_Types, is_trivially_copy_assignable, is_copy_assignable>...}); static constexpr _Trait __move_assignable_trait = __common_trait( {__move_constructible_trait, __trait<_Types, is_trivially_move_assignable, is_move_assignable>...}); static constexpr _Trait __destructible_trait = __common_trait( {__trait<_Types, is_trivially_destructible, is_destructible>...}); }; namespace __access { struct __union { template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<0>) { return _VSTD::forward<_Vp>(__v).__head; } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<_Ip>) { return __get_alt(_VSTD::forward<_Vp>(__v).__tail, in_place_index<_Ip - 1>); } }; struct __base { template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto&& __get_alt(_Vp&& __v) { return __union::__get_alt(_VSTD::forward<_Vp>(__v).__data, in_place_index<_Ip>); } }; struct __variant { template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto&& __get_alt(_Vp&& __v) { return __base::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v).__impl); } }; } // namespace __access namespace __visitation { struct __base { template inline _LIBCPP_INLINE_VISIBILITY static constexpr decltype(auto) __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { constexpr auto __fdiagonal = __make_fdiagonal<_Visitor&&, decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>(); return __fdiagonal[__index](_VSTD::forward<_Visitor>(__visitor), _VSTD::forward<_Vs>(__vs).__as_base()...); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, _Vs&&... __vs) { constexpr auto __fmatrix = __make_fmatrix<_Visitor&&, decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>(); const size_t __indices[] = {__vs.index()...}; return __at(__fmatrix, __indices)(_VSTD::forward<_Visitor>(__visitor), _VSTD::forward<_Vs>(__vs).__as_base()...); } private: template inline _LIBCPP_INLINE_VISIBILITY static constexpr const _Tp& __at_impl(const _Tp& __elem, const size_t*) { return __elem; } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto&& __at_impl(const array<_Tp, _Np>& __elems, const size_t* __index) { return __at_impl(__elems[*__index], __index + 1); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto&& __at(const array<_Tp, _Np>& __elems, const size_t (&__indices)[_Ip]) { return __at_impl(__elems, begin(__indices)); } template static constexpr void __std_visit_visitor_return_type_check() { static_assert( __all...>::value, "`std::visit` requires the visitor to have a single return type."); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_farray(_Fs&&... __fs) { __std_visit_visitor_return_type_check...>(); using __result = array...>, sizeof...(_Fs)>; return __result{{_VSTD::forward<_Fs>(__fs)...}}; } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_dispatch(index_sequence<_Is...>) { struct __dispatcher { static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) { return __invoke_constexpr( static_cast<_Fp>(__f), __access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...); } }; return _VSTD::addressof(__dispatcher::__dispatch); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_fdiagonal_impl() { return __make_dispatch<_Fp, _Vs...>( index_sequence<(__identity<_Vs>{}, _Ip)...>{}); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_fdiagonal_impl(index_sequence<_Is...>) { return __base::__make_farray(__make_fdiagonal_impl<_Is, _Fp, _Vs...>()...); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_fdiagonal() { constexpr size_t _Np = decay_t<_Vp>::__size(); static_assert(__all<(_Np == decay_t<_Vs>::__size())...>::value); return __make_fdiagonal_impl<_Fp, _Vp, _Vs...>(make_index_sequence<_Np>{}); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_fmatrix_impl(index_sequence<_Is...> __is) { return __make_dispatch<_Fp, _Vs...>(__is); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_fmatrix_impl(index_sequence<_Is...>, index_sequence<_Js...>, _Ls... __ls) { return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>( index_sequence<_Is..., _Js>{}, __ls...)...); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_fmatrix() { return __make_fmatrix_impl<_Fp, _Vs...>( index_sequence<>{}, make_index_sequence::__size()>{}...); } }; struct __variant { template inline _LIBCPP_INLINE_VISIBILITY static constexpr decltype(auto) __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { return __base::__visit_alt_at(__index, _VSTD::forward<_Visitor>(__visitor), _VSTD::forward<_Vs>(__vs).__impl...); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, _Vs&&... __vs) { return __base::__visit_alt(_VSTD::forward<_Visitor>(__visitor), _VSTD::forward<_Vs>(__vs).__impl...); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr decltype(auto) __visit_value_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { return __visit_alt_at( __index, __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)), _VSTD::forward<_Vs>(__vs)...); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr decltype(auto) __visit_value(_Visitor&& __visitor, _Vs&&... __vs) { return __visit_alt( __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)), _VSTD::forward<_Vs>(__vs)...); } private: template static constexpr void __std_visit_exhaustive_visitor_check() { static_assert(is_callable_v<_Visitor(_Values...)>, "`std::visit` requires the visitor to be exhaustive."); } template struct __value_visitor { template inline _LIBCPP_INLINE_VISIBILITY constexpr decltype(auto) operator()(_Alts&&... __alts) const { __std_visit_exhaustive_visitor_check< _Visitor, - decltype(_VSTD::forward<_Alts>(__alts).__value)...>(); + decltype((_VSTD::forward<_Alts>(__alts).__value))...>(); return __invoke_constexpr(_VSTD::forward<_Visitor>(__visitor), _VSTD::forward<_Alts>(__alts).__value...); } _Visitor&& __visitor; }; template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto __make_value_visitor(_Visitor&& __visitor) { return __value_visitor<_Visitor>{_VSTD::forward<_Visitor>(__visitor)}; } }; } // namespace __visitation template struct _LIBCPP_TEMPLATE_VIS __alt { using __value_type = _Tp; template inline _LIBCPP_INLINE_VISIBILITY explicit constexpr __alt(in_place_t, _Args&&... __args) : __value(_VSTD::forward<_Args>(__args)...) {} __value_type __value; }; template <_Trait _DestructibleTrait, size_t _Index, class... _Types> union _LIBCPP_TEMPLATE_VIS __union; template <_Trait _DestructibleTrait, size_t _Index> union _LIBCPP_TEMPLATE_VIS __union<_DestructibleTrait, _Index> {}; #define _LIBCPP_VARIANT_UNION(destructible_trait, destructor) \ template \ union _LIBCPP_TEMPLATE_VIS __union { \ public: \ inline _LIBCPP_INLINE_VISIBILITY \ explicit constexpr __union(__valueless_t) noexcept : __dummy{} {} \ \ template \ inline _LIBCPP_INLINE_VISIBILITY \ explicit constexpr __union(in_place_index_t<0>, _Args&&... __args) \ : __head(in_place, _VSTD::forward<_Args>(__args)...) {} \ \ template \ inline _LIBCPP_INLINE_VISIBILITY \ explicit constexpr __union(in_place_index_t<_Ip>, _Args&&... __args) \ : __tail(in_place_index<_Ip - 1>, _VSTD::forward<_Args>(__args)...) {} \ \ __union(const __union&) = default; \ __union(__union&&) = default; \ \ destructor \ \ __union& operator=(const __union&) = default; \ __union& operator=(__union&&) = default; \ \ private: \ char __dummy; \ __alt<_Index, _Tp> __head; \ __union __tail; \ \ friend struct __access::__union; \ } _LIBCPP_VARIANT_UNION(_Trait::_TriviallyAvailable, ~__union() = default;); _LIBCPP_VARIANT_UNION(_Trait::_Available, ~__union() {}); _LIBCPP_VARIANT_UNION(_Trait::_Unavailable, ~__union() = delete;); #undef _LIBCPP_VARIANT_UNION template <_Trait _DestructibleTrait, class... _Types> class _LIBCPP_TEMPLATE_VIS __base { public: inline _LIBCPP_INLINE_VISIBILITY explicit constexpr __base(__valueless_t tag) noexcept : __data(tag), __index(__variant_npos) {} template inline _LIBCPP_INLINE_VISIBILITY explicit constexpr __base(in_place_index_t<_Ip>, _Args&&... __args) : __data(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...), __index(_Ip) {} inline _LIBCPP_INLINE_VISIBILITY constexpr bool valueless_by_exception() const noexcept { return index() == variant_npos; } inline _LIBCPP_INLINE_VISIBILITY constexpr size_t index() const noexcept { return __index == __variant_npos ? variant_npos : __index; } protected: inline _LIBCPP_INLINE_VISIBILITY constexpr auto&& __as_base() & { return *this; } inline _LIBCPP_INLINE_VISIBILITY constexpr auto&& __as_base() && { return _VSTD::move(*this); } inline _LIBCPP_INLINE_VISIBILITY constexpr auto&& __as_base() const & { return *this; } inline _LIBCPP_INLINE_VISIBILITY constexpr auto&& __as_base() const && { return _VSTD::move(*this); } inline _LIBCPP_INLINE_VISIBILITY static constexpr size_t __size() { return sizeof...(_Types); } __union<_DestructibleTrait, 0, _Types...> __data; unsigned int __index; friend struct __access::__base; friend struct __visitation::__base; }; template class _LIBCPP_TEMPLATE_VIS __destructor; #define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor, destroy) \ template \ class _LIBCPP_TEMPLATE_VIS __destructor<__traits<_Types...>, \ destructible_trait> \ : public __base { \ using __base_type = __base; \ \ public: \ using __base_type::__base_type; \ using __base_type::operator=; \ \ __destructor(const __destructor&) = default; \ __destructor(__destructor&&) = default; \ destructor \ __destructor& operator=(const __destructor&) = default; \ __destructor& operator=(__destructor&&) = default; \ \ protected: \ inline _LIBCPP_INLINE_VISIBILITY \ destroy \ } _LIBCPP_VARIANT_DESTRUCTOR( _Trait::_TriviallyAvailable, ~__destructor() = default;, void __destroy() noexcept { this->__index = __variant_npos; }); _LIBCPP_VARIANT_DESTRUCTOR( _Trait::_Available, ~__destructor() { __destroy(); }, void __destroy() noexcept { if (!this->valueless_by_exception()) { __visitation::__base::__visit_alt( [](auto& __alt) noexcept { using __alt_type = decay_t; __alt.~__alt_type(); }, *this); } this->__index = __variant_npos; }); _LIBCPP_VARIANT_DESTRUCTOR( _Trait::_Unavailable, ~__destructor() = delete;, void __destroy() noexcept = delete;); #undef _LIBCPP_VARIANT_DESTRUCTOR template class _LIBCPP_TEMPLATE_VIS __constructor : public __destructor<_Traits> { using __base_type = __destructor<_Traits>; public: using __base_type::__base_type; using __base_type::operator=; protected: template inline _LIBCPP_INLINE_VISIBILITY static void __construct_alt(__alt<_Ip, _Tp>& __a, _Args&&... __args) { ::new (_VSTD::addressof(__a)) __alt<_Ip, _Tp>(in_place, _VSTD::forward<_Args>(__args)...); } template inline _LIBCPP_INLINE_VISIBILITY static void __generic_construct(__constructor& __lhs, _Rhs&& __rhs) { __lhs.__destroy(); if (!__rhs.valueless_by_exception()) { __visitation::__base::__visit_alt_at( __rhs.index(), [](auto& __lhs_alt, auto&& __rhs_alt) { __construct_alt( __lhs_alt, _VSTD::forward(__rhs_alt).__value); }, __lhs, _VSTD::forward<_Rhs>(__rhs)); __lhs.__index = __rhs.index(); } } }; template class _LIBCPP_TEMPLATE_VIS __move_constructor; #define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, \ move_constructor) \ template \ class _LIBCPP_TEMPLATE_VIS __move_constructor<__traits<_Types...>, \ move_constructible_trait> \ : public __constructor<__traits<_Types...>> { \ using __base_type = __constructor<__traits<_Types...>>; \ \ public: \ using __base_type::__base_type; \ using __base_type::operator=; \ \ __move_constructor(const __move_constructor&) = default; \ move_constructor \ ~__move_constructor() = default; \ __move_constructor& operator=(const __move_constructor&) = default; \ __move_constructor& operator=(__move_constructor&&) = default; \ } _LIBCPP_VARIANT_MOVE_CONSTRUCTOR( _Trait::_TriviallyAvailable, __move_constructor(__move_constructor&& __that) = default;); _LIBCPP_VARIANT_MOVE_CONSTRUCTOR( _Trait::_Available, __move_constructor(__move_constructor&& __that) noexcept( __all...>::value) : __move_constructor(__valueless_t{}) { this->__generic_construct(*this, _VSTD::move(__that)); }); _LIBCPP_VARIANT_MOVE_CONSTRUCTOR( _Trait::_Unavailable, __move_constructor(__move_constructor&&) = delete;); #undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR template class _LIBCPP_TEMPLATE_VIS __copy_constructor; #define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, \ copy_constructor) \ template \ class _LIBCPP_TEMPLATE_VIS __copy_constructor<__traits<_Types...>, \ copy_constructible_trait> \ : public __move_constructor<__traits<_Types...>> { \ using __base_type = __move_constructor<__traits<_Types...>>; \ \ public: \ using __base_type::__base_type; \ using __base_type::operator=; \ \ copy_constructor \ __copy_constructor(__copy_constructor&&) = default; \ ~__copy_constructor() = default; \ __copy_constructor& operator=(const __copy_constructor&) = default; \ __copy_constructor& operator=(__copy_constructor&&) = default; \ } _LIBCPP_VARIANT_COPY_CONSTRUCTOR( _Trait::_TriviallyAvailable, __copy_constructor(const __copy_constructor& __that) = default;); _LIBCPP_VARIANT_COPY_CONSTRUCTOR( _Trait::_Available, __copy_constructor(const __copy_constructor& __that) : __copy_constructor(__valueless_t{}) { this->__generic_construct(*this, __that); }); _LIBCPP_VARIANT_COPY_CONSTRUCTOR( _Trait::_Unavailable, __copy_constructor(const __copy_constructor&) = delete;); #undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR template class _LIBCPP_TEMPLATE_VIS __assignment : public __copy_constructor<_Traits> { using __base_type = __copy_constructor<_Traits>; public: using __base_type::__base_type; using __base_type::operator=; template inline _LIBCPP_INLINE_VISIBILITY void __emplace(_Args&&... __args) { this->__destroy(); this->__construct_alt(__access::__base::__get_alt<_Ip>(*this), _VSTD::forward<_Args>(__args)...); this->__index = _Ip; } protected: template inline _LIBCPP_INLINE_VISIBILITY void __assign_alt(__alt<_Ip, _Tp>& __a, _Arg&& __arg, bool_constant<_CopyAssign> __tag) { if (this->index() == _Ip) { __a.__value = _VSTD::forward<_Arg>(__arg); } else { struct { void operator()(true_type) const { __this->__emplace<_Ip>(_Tp(_VSTD::forward<_Arg>(__arg))); } void operator()(false_type) const { __this->__emplace<_Ip>(_VSTD::forward<_Arg>(__arg)); } __assignment* __this; _Arg&& __arg; } __impl{this, _VSTD::forward<_Arg>(__arg)}; __impl(__tag); } } template inline _LIBCPP_INLINE_VISIBILITY void __generic_assign(_That&& __that) { if (this->valueless_by_exception() && __that.valueless_by_exception()) { // do nothing. } else if (__that.valueless_by_exception()) { this->__destroy(); } else { __visitation::__base::__visit_alt_at( __that.index(), [this](auto& __this_alt, auto&& __that_alt) { this->__assign_alt( __this_alt, _VSTD::forward(__that_alt).__value, is_lvalue_reference<_That>{}); }, *this, _VSTD::forward<_That>(__that)); } } }; template class _LIBCPP_TEMPLATE_VIS __move_assignment; #define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, \ move_assignment) \ template \ class _LIBCPP_TEMPLATE_VIS __move_assignment<__traits<_Types...>, \ move_assignable_trait> \ : public __assignment<__traits<_Types...>> { \ using __base_type = __assignment<__traits<_Types...>>; \ \ public: \ using __base_type::__base_type; \ using __base_type::operator=; \ \ __move_assignment(const __move_assignment&) = default; \ __move_assignment(__move_assignment&&) = default; \ ~__move_assignment() = default; \ __move_assignment& operator=(const __move_assignment&) = default; \ move_assignment \ } _LIBCPP_VARIANT_MOVE_ASSIGNMENT( _Trait::_TriviallyAvailable, __move_assignment& operator=(__move_assignment&& __that) = default;); _LIBCPP_VARIANT_MOVE_ASSIGNMENT( _Trait::_Available, __move_assignment& operator=(__move_assignment&& __that) noexcept( __all<(is_nothrow_move_constructible_v<_Types> && is_nothrow_move_assignable_v<_Types>)...>::value) { this->__generic_assign(_VSTD::move(__that)); return *this; }); _LIBCPP_VARIANT_MOVE_ASSIGNMENT( _Trait::_Unavailable, __move_assignment& operator=(__move_assignment&&) = delete;); #undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT template class _LIBCPP_TEMPLATE_VIS __copy_assignment; #define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, \ copy_assignment) \ template \ class _LIBCPP_TEMPLATE_VIS __copy_assignment<__traits<_Types...>, \ copy_assignable_trait> \ : public __move_assignment<__traits<_Types...>> { \ using __base_type = __move_assignment<__traits<_Types...>>; \ \ public: \ using __base_type::__base_type; \ using __base_type::operator=; \ \ __copy_assignment(const __copy_assignment&) = default; \ __copy_assignment(__copy_assignment&&) = default; \ ~__copy_assignment() = default; \ copy_assignment \ __copy_assignment& operator=(__copy_assignment&&) = default; \ } _LIBCPP_VARIANT_COPY_ASSIGNMENT( _Trait::_TriviallyAvailable, __copy_assignment& operator=(const __copy_assignment& __that) = default;); _LIBCPP_VARIANT_COPY_ASSIGNMENT( _Trait::_Available, __copy_assignment& operator=(const __copy_assignment& __that) { this->__generic_assign(__that); return *this; }); _LIBCPP_VARIANT_COPY_ASSIGNMENT( _Trait::_Unavailable, __copy_assignment& operator=(const __copy_assignment&) = delete;); #undef _LIBCPP_VARIANT_COPY_ASSIGNMENT template class _LIBCPP_TEMPLATE_VIS __impl : public __copy_assignment<__traits<_Types...>> { using __base_type = __copy_assignment<__traits<_Types...>>; public: using __base_type::__base_type; using __base_type::operator=; template inline _LIBCPP_INLINE_VISIBILITY void __assign(_Arg&& __arg) { this->__assign_alt(__access::__base::__get_alt<_Ip>(*this), _VSTD::forward<_Arg>(__arg), false_type{}); } inline _LIBCPP_INLINE_VISIBILITY void __swap(__impl& __that) { if (this->valueless_by_exception() && __that.valueless_by_exception()) { // do nothing. } else if (this->index() == __that.index()) { __visitation::__base::__visit_alt_at( this->index(), [](auto& __this_alt, auto& __that_alt) { using _VSTD::swap; swap(__this_alt.__value, __that_alt.__value); }, *this, __that); } else { __impl* __lhs = this; __impl* __rhs = _VSTD::addressof(__that); if (__lhs->__move_nothrow() && !__rhs->__move_nothrow()) { _VSTD::swap(__lhs, __rhs); } __impl __tmp(_VSTD::move(*__rhs)); #ifndef _LIBCPP_NO_EXCEPTIONS // EXTENSION: When the move construction of `__lhs` into `__rhs` throws // and `__tmp` is nothrow move constructible then we move `__tmp` back // into `__rhs` and provide the strong exception safety guarentee. try { this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); } catch (...) { if (__tmp.__move_nothrow()) { this->__generic_construct(*__rhs, _VSTD::move(__tmp)); } throw; } #else this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); #endif this->__generic_construct(*__lhs, _VSTD::move(__tmp)); } } private: inline _LIBCPP_INLINE_VISIBILITY bool __move_nothrow() const { constexpr bool __results[] = {is_nothrow_move_constructible_v<_Types>...}; return this->valueless_by_exception() || __results[this->index()]; } }; template struct __overload; template <> struct __overload<> { void operator()() const; }; template struct __overload<_Tp, _Types...> : __overload<_Types...> { using __overload<_Types...>::operator(); __identity<_Tp> operator()(_Tp) const; }; template using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type; } // __variant_detail template class _LIBCPP_TEMPLATE_VIS variant : private __sfinae_ctor_base< __all...>::value, __all...>::value>, private __sfinae_assign_base< __all<(is_copy_constructible_v<_Types> && is_move_constructible_v<_Types> && is_copy_assignable_v<_Types>)...>::value, __all<(is_move_constructible_v<_Types> && is_move_assignable_v<_Types>)...>::value> { static_assert(0 < sizeof...(_Types), "variant must consist of at least one alternative."); static_assert(__all...>::value, "variant can not have an array type as an alternative."); static_assert(__all...>::value, "variant can not have a reference type as an alternative."); static_assert(__all...>::value, "variant can not have a void type as an alternative."); using __first_type = variant_alternative_t<0, variant>; public: template , _Dummy>::value, int> = 0> inline _LIBCPP_INLINE_VISIBILITY constexpr variant() noexcept(is_nothrow_default_constructible_v<__first_type>) : __impl(in_place_index<0>) {} variant(const variant&) = default; variant(variant&&) = default; template < class _Arg, enable_if_t, variant>, int> = 0, class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>, size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, enable_if_t, int> = 0> inline _LIBCPP_INLINE_VISIBILITY constexpr variant(_Arg&& __arg) noexcept( is_nothrow_constructible_v<_Tp, _Arg>) : __impl(in_place_index<_Ip>, _VSTD::forward<_Arg>(__arg)) {} template = 0, class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, enable_if_t, int> = 0> inline _LIBCPP_INLINE_VISIBILITY explicit constexpr variant( in_place_index_t<_Ip>, _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, _Args...>) : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} template < size_t _Ip, class _Up, class... _Args, enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, enable_if_t&, _Args...>, int> = 0> inline _LIBCPP_INLINE_VISIBILITY explicit constexpr variant( in_place_index_t<_Ip>, initializer_list<_Up> __il, _Args&&... __args) noexcept( is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>) : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {} template < class _Tp, class... _Args, size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, enable_if_t, int> = 0> inline _LIBCPP_INLINE_VISIBILITY explicit constexpr variant(in_place_type_t<_Tp>, _Args&&... __args) noexcept( is_nothrow_constructible_v<_Tp, _Args...>) : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} template < class _Tp, class _Up, class... _Args, size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, enable_if_t&, _Args...>, int> = 0> inline _LIBCPP_INLINE_VISIBILITY explicit constexpr variant( in_place_type_t<_Tp>, initializer_list<_Up> __il, _Args&&... __args) noexcept( is_nothrow_constructible_v<_Tp, initializer_list< _Up>&, _Args...>) : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {} ~variant() = default; variant& operator=(const variant&) = default; variant& operator=(variant&&) = default; template < class _Arg, enable_if_t, variant>, int> = 0, class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>, size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, enable_if_t && is_constructible_v<_Tp, _Arg>, int> = 0> inline _LIBCPP_INLINE_VISIBILITY variant& operator=(_Arg&& __arg) noexcept( is_nothrow_assignable_v<_Tp&, _Arg> && is_nothrow_constructible_v<_Tp, _Arg>) { __impl.template __assign<_Ip>(_VSTD::forward<_Arg>(__arg)); return *this; } template < size_t _Ip, class... _Args, enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, enable_if_t, int> = 0> inline _LIBCPP_INLINE_VISIBILITY void emplace(_Args&&... __args) { __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...); } template < size_t _Ip, class _Up, class... _Args, enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, enable_if_t&, _Args...>, int> = 0> inline _LIBCPP_INLINE_VISIBILITY void emplace(initializer_list<_Up> __il, _Args&&... __args) { __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...); } template < class _Tp, class... _Args, size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, enable_if_t, int> = 0> inline _LIBCPP_INLINE_VISIBILITY void emplace(_Args&&... __args) { __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...); } template < class _Tp, class _Up, class... _Args, size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, enable_if_t&, _Args...>, int> = 0> inline _LIBCPP_INLINE_VISIBILITY void emplace(initializer_list<_Up> __il, _Args&&... __args) { __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...); } inline _LIBCPP_INLINE_VISIBILITY constexpr bool valueless_by_exception() const noexcept { return __impl.valueless_by_exception(); } inline _LIBCPP_INLINE_VISIBILITY constexpr size_t index() const noexcept { return __impl.index(); } template < bool _Dummy = true, enable_if_t< __all<( __dependent_type, _Dummy>::value && __dependent_type, _Dummy>::value)...>::value, int> = 0> inline _LIBCPP_INLINE_VISIBILITY void swap(variant& __that) noexcept( __all<(is_nothrow_move_constructible_v<_Types> && is_nothrow_swappable_v<_Types>)...>::value) { __impl.__swap(__that.__impl); } private: __variant_detail::__impl<_Types...> __impl; friend struct __variant_detail::__access::__variant; friend struct __variant_detail::__visitation::__variant; }; template inline _LIBCPP_INLINE_VISIBILITY constexpr bool __holds_alternative(const variant<_Types...>& __v) noexcept { return __v.index() == _Ip; } template inline _LIBCPP_INLINE_VISIBILITY constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept { return __holds_alternative<__find_exactly_one_t<_Tp, _Types...>::value>(__v); } template inline _LIBCPP_INLINE_VISIBILITY static constexpr auto&& __generic_get(_Vp&& __v) { using __variant_detail::__access::__variant; if (!__holds_alternative<_Ip>(__v)) { __throw_bad_variant_access(); } return __variant::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v)).__value; } template inline _LIBCPP_INLINE_VISIBILITY constexpr variant_alternative_t<_Ip, variant<_Types...>>& get( variant<_Types...>& __v) { static_assert(_Ip < sizeof...(_Types)); static_assert(!is_void_v>>); return __generic_get<_Ip>(__v); } template inline _LIBCPP_INLINE_VISIBILITY constexpr variant_alternative_t<_Ip, variant<_Types...>>&& get( variant<_Types...>&& __v) { static_assert(_Ip < sizeof...(_Types)); static_assert(!is_void_v>>); return __generic_get<_Ip>(_VSTD::move(__v)); } template inline _LIBCPP_INLINE_VISIBILITY constexpr const variant_alternative_t<_Ip, variant<_Types...>>& get( const variant<_Types...>& __v) { static_assert(_Ip < sizeof...(_Types)); static_assert(!is_void_v>>); return __generic_get<_Ip>(__v); } template inline _LIBCPP_INLINE_VISIBILITY constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& get( const variant<_Types...>&& __v) { static_assert(_Ip < sizeof...(_Types)); static_assert(!is_void_v>>); return __generic_get<_Ip>(_VSTD::move(__v)); } template inline _LIBCPP_INLINE_VISIBILITY constexpr _Tp& get(variant<_Types...>& __v) { static_assert(!is_void_v<_Tp>); return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v); } template inline _LIBCPP_INLINE_VISIBILITY constexpr _Tp&& get(variant<_Types...>&& __v) { static_assert(!is_void_v<_Tp>); return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>( _VSTD::move(__v)); } template inline _LIBCPP_INLINE_VISIBILITY constexpr const _Tp& get(const variant<_Types...>& __v) { static_assert(!is_void_v<_Tp>); return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v); } template inline _LIBCPP_INLINE_VISIBILITY constexpr const _Tp&& get(const variant<_Types...>&& __v) { static_assert(!is_void_v<_Tp>); return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>( _VSTD::move(__v)); } template inline _LIBCPP_INLINE_VISIBILITY constexpr auto* __generic_get_if(_Vp* __v) noexcept { using __variant_detail::__access::__variant; return __v && __holds_alternative<_Ip>(*__v) ? _VSTD::addressof(__variant::__get_alt<_Ip>(*__v).__value) : nullptr; } template inline _LIBCPP_INLINE_VISIBILITY constexpr add_pointer_t>> get_if(variant<_Types...>* __v) noexcept { static_assert(_Ip < sizeof...(_Types)); static_assert(!is_void_v>>); return __generic_get_if<_Ip>(__v); } template inline _LIBCPP_INLINE_VISIBILITY constexpr add_pointer_t>> get_if(const variant<_Types...>* __v) noexcept { static_assert(_Ip < sizeof...(_Types)); static_assert(!is_void_v>>); return __generic_get_if<_Ip>(__v); } template inline _LIBCPP_INLINE_VISIBILITY constexpr add_pointer_t<_Tp> get_if(variant<_Types...>* __v) noexcept { static_assert(!is_void_v<_Tp>); return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v); } template inline _LIBCPP_INLINE_VISIBILITY constexpr add_pointer_t get_if(const variant<_Types...>* __v) noexcept { static_assert(!is_void_v<_Tp>); return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v); } template inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator==(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) { using __variant_detail::__visitation::__variant; if (__lhs.index() != __rhs.index()) return false; if (__lhs.valueless_by_exception()) return true; return __variant::__visit_value_at(__lhs.index(), equal_to<>{}, __lhs, __rhs); } template inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator!=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) { using __variant_detail::__visitation::__variant; if (__lhs.index() != __rhs.index()) return true; if (__lhs.valueless_by_exception()) return false; return __variant::__visit_value_at( __lhs.index(), not_equal_to<>{}, __lhs, __rhs); } template inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator<(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) { using __variant_detail::__visitation::__variant; if (__rhs.valueless_by_exception()) return false; if (__lhs.valueless_by_exception()) return true; if (__lhs.index() < __rhs.index()) return true; if (__lhs.index() > __rhs.index()) return false; return __variant::__visit_value_at(__lhs.index(), less<>{}, __lhs, __rhs); } template inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator>(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) { using __variant_detail::__visitation::__variant; if (__lhs.valueless_by_exception()) return false; if (__rhs.valueless_by_exception()) return true; if (__lhs.index() > __rhs.index()) return true; if (__lhs.index() < __rhs.index()) return false; return __variant::__visit_value_at(__lhs.index(), greater<>{}, __lhs, __rhs); } template inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator<=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) { using __variant_detail::__visitation::__variant; if (__lhs.valueless_by_exception()) return true; if (__rhs.valueless_by_exception()) return false; if (__lhs.index() < __rhs.index()) return true; if (__lhs.index() > __rhs.index()) return false; return __variant::__visit_value_at( __lhs.index(), less_equal<>{}, __lhs, __rhs); } template inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator>=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) { using __variant_detail::__visitation::__variant; if (__rhs.valueless_by_exception()) return true; if (__lhs.valueless_by_exception()) return false; if (__lhs.index() > __rhs.index()) return true; if (__lhs.index() < __rhs.index()) return false; return __variant::__visit_value_at( __lhs.index(), greater_equal<>{}, __lhs, __rhs); } template inline _LIBCPP_INLINE_VISIBILITY constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) { using __variant_detail::__visitation::__variant; bool __results[] = {__vs.valueless_by_exception()...}; for (bool __result : __results) { if (__result) { __throw_bad_variant_access(); } } return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor), _VSTD::forward<_Vs>(__vs)...); } struct _LIBCPP_TEMPLATE_VIS monostate {}; inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator<(monostate, monostate) noexcept { return false; } inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator>(monostate, monostate) noexcept { return false; } inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator<=(monostate, monostate) noexcept { return true; } inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator>=(monostate, monostate) noexcept { return true; } inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator==(monostate, monostate) noexcept { return true; } inline _LIBCPP_INLINE_VISIBILITY constexpr bool operator!=(monostate, monostate) noexcept { return false; } template inline _LIBCPP_INLINE_VISIBILITY auto swap(variant<_Types...>& __lhs, variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs))) -> decltype(__lhs.swap(__rhs)) { __lhs.swap(__rhs); } template struct _LIBCPP_TEMPLATE_VIS hash> { using argument_type = variant<_Types...>; using result_type = size_t; inline _LIBCPP_INLINE_VISIBILITY result_type operator()(const argument_type& __v) const { using __variant_detail::__visitation::__variant; size_t __res = __v.valueless_by_exception() ? 299792458 // Random value chosen by the universe upon creation : __variant::__visit_alt( [](const auto& __alt) { using __alt_type = decay_t; using __value_type = typename __alt_type::__value_type; return hash<__value_type>{}(__alt.__value); }, __v); return __hash_combine(__res, hash{}(__v.index())); } }; template <> struct _LIBCPP_TEMPLATE_VIS hash { using argument_type = monostate; using result_type = size_t; inline _LIBCPP_INLINE_VISIBILITY result_type operator()(const argument_type&) const { return 66740831; // return a fundamentally attractive random value. } }; #endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_VARIANT Index: vendor/libc++/dist/src/optional.cpp =================================================================== --- vendor/libc++/dist/src/optional.cpp (revision 313637) +++ vendor/libc++/dist/src/optional.cpp (revision 313638) @@ -1,24 +1,28 @@ //===------------------------ optional.cpp --------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "optional" #include "experimental/optional" namespace std { bad_optional_access::~bad_optional_access() _NOEXCEPT = default; +const char* bad_optional_access::what() const _NOEXCEPT { + return "bad_optional_access"; + } + } // std _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL bad_optional_access::~bad_optional_access() _NOEXCEPT = default; _LIBCPP_END_NAMESPACE_EXPERIMENTAL Index: vendor/libc++/dist/test/std/utilities/optional/optional.bad_optional_access/derive.pass.cpp =================================================================== --- vendor/libc++/dist/test/std/utilities/optional/optional.bad_optional_access/derive.pass.cpp (revision 313637) +++ vendor/libc++/dist/test/std/utilities/optional/optional.bad_optional_access/derive.pass.cpp (revision 313638) @@ -1,25 +1,25 @@ //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11, c++14 // -// class bad_optional_access : public logic_error +// class bad_optional_access : public exception #include #include int main() { using std::bad_optional_access; - static_assert(std::is_base_of::value, ""); - static_assert(std::is_convertible::value, ""); + static_assert(std::is_base_of::value, ""); + static_assert(std::is_convertible::value, ""); } Index: vendor/libc++/dist/test/std/utilities/variant/variant.visit/visit.pass.cpp =================================================================== --- vendor/libc++/dist/test/std/utilities/variant/variant.visit/visit.pass.cpp (revision 313637) +++ vendor/libc++/dist/test/std/utilities/variant/variant.visit/visit.pass.cpp (revision 313638) @@ -1,291 +1,302 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11, c++14 // // template // constexpr see below visit(Visitor&& vis, Variants&&... vars); #include #include #include #include #include #include #include "test_macros.h" #include "type_id.h" #include "variant_test_helpers.hpp" enum CallType : unsigned { CT_None, CT_NonConst = 1, CT_Const = 2, CT_LValue = 4, CT_RValue = 8 }; inline constexpr CallType operator|(CallType LHS, CallType RHS) { return static_cast(static_cast(LHS) | static_cast(RHS)); } struct ForwardingCallObject { template bool operator()(Args &&...) & { set_call(CT_NonConst | CT_LValue); return true; } template bool operator()(Args &&...) const & { set_call(CT_Const | CT_LValue); return true; } // Don't allow the call operator to be invoked as an rvalue. template bool operator()(Args &&...) && { set_call(CT_NonConst | CT_RValue); return true; } template bool operator()(Args &&...) const && { set_call(CT_Const | CT_RValue); return true; } template static void set_call(CallType type) { assert(last_call_type == CT_None); assert(last_call_args == nullptr); last_call_type = type; last_call_args = std::addressof(makeArgumentID()); } template static bool check_call(CallType type) { bool result = last_call_type == type && last_call_args && *last_call_args == makeArgumentID(); last_call_type = CT_None; last_call_args = nullptr; return result; } static CallType last_call_type; static const TypeID *last_call_args; }; CallType ForwardingCallObject::last_call_type = CT_None; const TypeID *ForwardingCallObject::last_call_args = nullptr; void test_call_operator_forwarding() { using Fn = ForwardingCallObject; Fn obj{}; const Fn &cobj = obj; { // test call operator forwarding - single variant, single arg using V = std::variant; V v(42); std::visit(obj, v); assert(Fn::check_call(CT_NonConst | CT_LValue)); std::visit(cobj, v); assert(Fn::check_call(CT_Const | CT_LValue)); std::visit(std::move(obj), v); assert(Fn::check_call(CT_NonConst | CT_RValue)); std::visit(std::move(cobj), v); assert(Fn::check_call(CT_Const | CT_RValue)); } { // test call operator forwarding - single variant, multi arg using V = std::variant; V v(42l); std::visit(obj, v); assert(Fn::check_call(CT_NonConst | CT_LValue)); std::visit(cobj, v); assert(Fn::check_call(CT_Const | CT_LValue)); std::visit(std::move(obj), v); assert(Fn::check_call(CT_NonConst | CT_RValue)); std::visit(std::move(cobj), v); assert(Fn::check_call(CT_Const | CT_RValue)); } { // test call operator forwarding - multi variant, multi arg using V = std::variant; using V2 = std::variant; V v(42l); V2 v2("hello"); std::visit(obj, v, v2); assert((Fn::check_call(CT_NonConst | CT_LValue))); std::visit(cobj, v, v2); assert((Fn::check_call(CT_Const | CT_LValue))); std::visit(std::move(obj), v, v2); assert((Fn::check_call(CT_NonConst | CT_RValue))); std::visit(std::move(cobj), v, v2); assert((Fn::check_call(CT_Const | CT_RValue))); } } void test_argument_forwarding() { using Fn = ForwardingCallObject; Fn obj{}; const auto Val = CT_LValue | CT_NonConst; { // single argument - value type using V = std::variant; V v(42); const V &cv = v; std::visit(obj, v); assert(Fn::check_call(Val)); std::visit(obj, cv); assert(Fn::check_call(Val)); std::visit(obj, std::move(v)); assert(Fn::check_call(Val)); std::visit(obj, std::move(cv)); assert(Fn::check_call(Val)); } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { // single argument - lvalue reference using V = std::variant; int x = 42; V v(x); const V &cv = v; std::visit(obj, v); assert(Fn::check_call(Val)); std::visit(obj, cv); assert(Fn::check_call(Val)); std::visit(obj, std::move(v)); assert(Fn::check_call(Val)); std::visit(obj, std::move(cv)); assert(Fn::check_call(Val)); } { // single argument - rvalue reference using V = std::variant; int x = 42; V v(std::move(x)); const V &cv = v; std::visit(obj, v); assert(Fn::check_call(Val)); std::visit(obj, cv); assert(Fn::check_call(Val)); std::visit(obj, std::move(v)); assert(Fn::check_call(Val)); std::visit(obj, std::move(cv)); assert(Fn::check_call(Val)); } { // multi argument - multi variant using S = const std::string &; using V = std::variant; const std::string str = "hello"; long l = 43; V v1(42); const V &cv1 = v1; V v2(str); const V &cv2 = v2; V v3(std::move(l)); const V &cv3 = v3; std::visit(obj, v1, v2, v3); assert((Fn::check_call(Val))); std::visit(obj, cv1, cv2, std::move(v3)); assert((Fn::check_call(Val))); } #endif } struct ReturnFirst { template constexpr int operator()(int f, Args &&...) const { return f; } }; struct ReturnArity { template constexpr int operator()(Args &&...) const { return sizeof...(Args); } }; void test_constexpr() { constexpr ReturnFirst obj{}; constexpr ReturnArity aobj{}; { using V = std::variant; constexpr V v(42); static_assert(std::visit(obj, v) == 42, ""); } { using V = std::variant; constexpr V v(42l); static_assert(std::visit(obj, v) == 42, ""); } { using V1 = std::variant; using V2 = std::variant; using V3 = std::variant; constexpr V1 v1; constexpr V2 v2(nullptr); constexpr V3 v3; static_assert(std::visit(aobj, v1, v2, v3) == 3, ""); } { using V1 = std::variant; using V2 = std::variant; using V3 = std::variant; constexpr V1 v1; constexpr V2 v2(nullptr); constexpr V3 v3; static_assert(std::visit(aobj, v1, v2, v3) == 3, ""); } } void test_exceptions() { #ifndef TEST_HAS_NO_EXCEPTIONS ReturnArity obj{}; auto test = [&](auto &&... args) { try { std::visit(obj, args...); } catch (const std::bad_variant_access &) { return true; } catch (...) { } return false; }; { using V = std::variant; V v; makeEmpty(v); assert(test(v)); } { using V = std::variant; using V2 = std::variant; V v; makeEmpty(v); V2 v2("hello"); assert(test(v, v2)); } { using V = std::variant; using V2 = std::variant; V v; makeEmpty(v); V2 v2("hello"); assert(test(v2, v)); } { using V = std::variant; using V2 = std::variant; V v; makeEmpty(v); V2 v2; makeEmpty(v2); assert(test(v, v2)); } #endif } +// See http://llvm.org/PR31916 +void test_caller_accepts_nonconst() { + struct A {}; + struct Visitor { + void operator()(A&) {} + }; + std::variant v; + std::visit(Visitor{}, v); +} + int main() { test_call_operator_forwarding(); test_argument_forwarding(); test_constexpr(); test_exceptions(); + test_caller_accepts_nonconst(); }