gcc/libstdc++-v3/testsuite/20_util/any/make_any.cc

58 lines
1.9 KiB
C++
Raw Normal View History

Implement P0032R3, Homogeneous interface for variant, any and optional, for the parts concerning any and optional. * include/std/any (_Storage()): Make constexpr and have it initialize _M_ptr. (any()): Make constexpr. (any(const any&)): Adjust. (any(any&&)): Likewise. (__any_constructible_t): New. (any(_ValueType&&)): Constrain. (any(in_place_type_t<_Tp>, _Args&&...)): New. (any(in_place_type_t<_Tp>, initializer_list<_Up>, _Args&&...)): Likewise. (~any()): Adjust. (operator=(const any&)): Likewise. (operator=(any&&)): Likewise. (operator=(_ValueType&&)): Constrain. (emplace(_Args&&...)): New. (emplace(initializer_list<_Up>, _Args&&...)): Likewise. (clear()): Remove. (reset()): New. (swap(any&)): Adjust. (empty()): Remove. (has_value()): New. (type()): Adjust. (_Manager_internal::_S_create(_Storage&, _Args&&...)): New. (_Manager_external::_S_create(_Storage&, _Args&&...)): Likewise. (make_any(_Args&&...)): Likewise. (make_any(initializer_list<_Up>, _Args&&...)): Likewise. * include/std/optional (in_place_t, in_place): Remove. (bad_optional_access): Add a comment referring to LEWG 72. (emplace(_Args&&...)): Constrain. (has_value()): New. (reset()): Likewise. (make_optional(_Args&&...)): Likewise. (make_optional(initializer_list<_Up>, _Args&&...)): Likewise. * include/std/utility (in_place_tag): New. (__in_place, __in_place_type, __in_place_index): Likewise. (in_place_t, in_place_type_t, in_place_index_t): Likewise. (in_place(__in_place*)): Likewise. (in_place(__in_place_type<_Tp>*)): Likewise. (in_place(__in_place_index<_Idx>*)): Likewise. * testsuite/20_util/any/assign/1.cc: Adjust. * testsuite/20_util/any/assign/emplace.cc: New. * testsuite/20_util/any/assign/self.cc: Adjust. * testsuite/20_util/any/cons/1.cc: Likewise. * testsuite/20_util/any/cons/in_place.cc: New. * testsuite/20_util/any/make_any.cc: Likewise. * testsuite/20_util/any/misc/any_cast_neg.cc: Adjust. * testsuite/20_util/any/misc/swap.cc: Likewise. * testsuite/20_util/any/modifiers/1.cc: Likewise. * testsuite/20_util/any/requirements.cc: New. * testsuite/20_util/in_place/requirements.cc: Likewise. * testsuite/20_util/optional/constexpr/in_place.cc: Adjust. * testsuite/20_util/optional/in_place.cc: Likewise. * testsuite/20_util/optional/make_optional.cc: Add tests for the new overloads of make_optional. From-SVN: r238329
2016-07-14 11:10:05 +02:00
// { dg-options "-std=gnu++17" }
// { dg-do run }
// Copyright (C) 2016-2017 Free Software Foundation, Inc.
Implement P0032R3, Homogeneous interface for variant, any and optional, for the parts concerning any and optional. * include/std/any (_Storage()): Make constexpr and have it initialize _M_ptr. (any()): Make constexpr. (any(const any&)): Adjust. (any(any&&)): Likewise. (__any_constructible_t): New. (any(_ValueType&&)): Constrain. (any(in_place_type_t<_Tp>, _Args&&...)): New. (any(in_place_type_t<_Tp>, initializer_list<_Up>, _Args&&...)): Likewise. (~any()): Adjust. (operator=(const any&)): Likewise. (operator=(any&&)): Likewise. (operator=(_ValueType&&)): Constrain. (emplace(_Args&&...)): New. (emplace(initializer_list<_Up>, _Args&&...)): Likewise. (clear()): Remove. (reset()): New. (swap(any&)): Adjust. (empty()): Remove. (has_value()): New. (type()): Adjust. (_Manager_internal::_S_create(_Storage&, _Args&&...)): New. (_Manager_external::_S_create(_Storage&, _Args&&...)): Likewise. (make_any(_Args&&...)): Likewise. (make_any(initializer_list<_Up>, _Args&&...)): Likewise. * include/std/optional (in_place_t, in_place): Remove. (bad_optional_access): Add a comment referring to LEWG 72. (emplace(_Args&&...)): Constrain. (has_value()): New. (reset()): Likewise. (make_optional(_Args&&...)): Likewise. (make_optional(initializer_list<_Up>, _Args&&...)): Likewise. * include/std/utility (in_place_tag): New. (__in_place, __in_place_type, __in_place_index): Likewise. (in_place_t, in_place_type_t, in_place_index_t): Likewise. (in_place(__in_place*)): Likewise. (in_place(__in_place_type<_Tp>*)): Likewise. (in_place(__in_place_index<_Idx>*)): Likewise. * testsuite/20_util/any/assign/1.cc: Adjust. * testsuite/20_util/any/assign/emplace.cc: New. * testsuite/20_util/any/assign/self.cc: Adjust. * testsuite/20_util/any/cons/1.cc: Likewise. * testsuite/20_util/any/cons/in_place.cc: New. * testsuite/20_util/any/make_any.cc: Likewise. * testsuite/20_util/any/misc/any_cast_neg.cc: Adjust. * testsuite/20_util/any/misc/swap.cc: Likewise. * testsuite/20_util/any/modifiers/1.cc: Likewise. * testsuite/20_util/any/requirements.cc: New. * testsuite/20_util/in_place/requirements.cc: Likewise. * testsuite/20_util/optional/constexpr/in_place.cc: Adjust. * testsuite/20_util/optional/in_place.cc: Likewise. * testsuite/20_util/optional/make_optional.cc: Add tests for the new overloads of make_optional. From-SVN: r238329
2016-07-14 11:10:05 +02:00
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
Fix find&replace error in license boilerplate * testsuite/19_diagnostics/error_code/is_error_code_v.cc: Fix license text. * testsuite/20_util/any/assign/emplace.cc: Likewise. * testsuite/20_util/any/cons/in_place.cc: Likewise. * testsuite/20_util/any/make_any.cc: Likewise. * testsuite/20_util/any/requirements.cc: Likewise. * testsuite/20_util/any/typedefs.cc: Likewise. * testsuite/20_util/bind/is_placeholder_v.cc: Likewise. * testsuite/20_util/duration/requirements/treat_as_floating_point_v.cc: Likewise. * testsuite/20_util/in_place/requirements.cc: Likewise. * testsuite/20_util/optional/77288.cc: Likewise. * testsuite/20_util/optional/assignment/1.cc: Likewise. * testsuite/20_util/optional/assignment/2.cc: Likewise. * testsuite/20_util/optional/assignment/3.cc: Likewise. * testsuite/20_util/optional/assignment/4.cc: Likewise. * testsuite/20_util/optional/assignment/5.cc: Likewise. * testsuite/20_util/optional/assignment/6.cc: Likewise. * testsuite/20_util/optional/assignment/7.cc: Likewise. * testsuite/20_util/optional/cons/77727.cc: Likewise. * testsuite/20_util/optional/cons/move.cc: Likewise. * testsuite/20_util/optional/cons/value.cc: Likewise. * testsuite/20_util/optional/cons/value_neg.cc: Likewise. * testsuite/20_util/optional/constexpr/cons/value.cc: Likewise. * testsuite/20_util/optional/constexpr/make_optional.cc: Likewise. * testsuite/20_util/optional/constexpr/observers/1.cc: Likewise. * testsuite/20_util/optional/constexpr/observers/2.cc: Likewise. * testsuite/20_util/optional/constexpr/observers/3.cc: Likewise. * testsuite/20_util/optional/constexpr/observers/4.cc: Likewise. * testsuite/20_util/optional/constexpr/observers/5.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/1.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/2.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/3.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/4.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/5.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/6.cc: Likewise. * testsuite/20_util/optional/hash.cc: Likewise. * testsuite/20_util/optional/make_optional.cc: Likewise. * testsuite/20_util/optional/observers/1.cc: Likewise. * testsuite/20_util/optional/observers/2.cc: Likewise. * testsuite/20_util/optional/observers/3.cc: Likewise. * testsuite/20_util/optional/observers/4.cc: Likewise. * testsuite/20_util/optional/observers/5.cc: Likewise. * testsuite/20_util/optional/observers/6.cc: Likewise. * testsuite/20_util/optional/relops/1.cc: Likewise. * testsuite/20_util/optional/relops/2.cc: Likewise. * testsuite/20_util/optional/relops/3.cc: Likewise. * testsuite/20_util/optional/relops/4.cc: Likewise. * testsuite/20_util/optional/relops/5.cc: Likewise. * testsuite/20_util/optional/relops/6.cc: Likewise. * testsuite/20_util/optional/requirements.cc: Likewise. * testsuite/20_util/optional/swap/1.cc: Likewise. * testsuite/20_util/optional/typedefs.cc: Likewise. * testsuite/20_util/ratio/requirements/ratio_equal_v.cc: Likewise. * testsuite/20_util/tuple/tuple_size_v.cc: Likewise. * testsuite/20_util/uses_allocator/requirements/uses_allocator_v.cc: Likewise. * testsuite/20_util/variable_templates_for_traits.cc: Likewise. * testsuite/20_util/variant/hash.cc: Likewise. * testsuite/21_strings/basic_string_view/typedefs.cc: Likewise. * testsuite/experimental/any/typedefs.cc: Likewise. * testsuite/experimental/array/make_array.cc: Likewise. * testsuite/experimental/array/neg.cc: Likewise. * testsuite/experimental/chrono/value.cc: Likewise. * testsuite/experimental/deque/erasure.cc: Likewise. * testsuite/experimental/forward_list/erasure.cc: Likewise. * testsuite/experimental/list/erasure.cc: Likewise. * testsuite/experimental/map/erasure.cc: Likewise. * testsuite/experimental/memory/observer_ptr/assignment/assign.cc: Likewise. * testsuite/experimental/memory/observer_ptr/cons/cons.cc: Likewise. * testsuite/experimental/memory/observer_ptr/hash/hash.cc: Likewise. * testsuite/experimental/memory/observer_ptr/make_observer.cc: Likewise. * testsuite/experimental/memory/observer_ptr/relops/relops.cc: Likewise. * testsuite/experimental/memory/observer_ptr/requirements.cc: Likewise. * testsuite/experimental/memory/observer_ptr/swap/swap.cc: Likewise. * testsuite/experimental/memory/observer_ptr/typedefs.cc: Likewise. * testsuite/experimental/optional/77288.cc: Likewise. * testsuite/experimental/optional/assignment/1.cc: Likewise. * testsuite/experimental/optional/assignment/2.cc: Likewise. * testsuite/experimental/optional/assignment/3.cc: Likewise. * testsuite/experimental/optional/assignment/4.cc: Likewise. * testsuite/experimental/optional/assignment/5.cc: Likewise. * testsuite/experimental/optional/assignment/6.cc: Likewise. * testsuite/experimental/optional/cons/77727.cc: Likewise. * testsuite/experimental/optional/cons/move.cc: Likewise. * testsuite/experimental/optional/cons/value.cc: Likewise. * testsuite/experimental/optional/cons/value_neg.cc: Likewise. * testsuite/experimental/optional/constexpr/cons/value.cc: Likewise. * testsuite/experimental/optional/constexpr/make_optional.cc: Likewise. * testsuite/experimental/optional/constexpr/observers/1.cc: Likewise. * testsuite/experimental/optional/constexpr/observers/2.cc: Likewise. * testsuite/experimental/optional/constexpr/observers/3.cc: Likewise. * testsuite/experimental/optional/constexpr/observers/4.cc: Likewise. * testsuite/experimental/optional/constexpr/observers/5.cc: Likewise. * testsuite/experimental/optional/constexpr/relops/1.cc: Likewise. * testsuite/experimental/optional/constexpr/relops/2.cc: Likewise. * testsuite/experimental/optional/constexpr/relops/3.cc: Likewise. * testsuite/experimental/optional/constexpr/relops/4.cc: Likewise. * testsuite/experimental/optional/constexpr/relops/5.cc: Likewise. * testsuite/experimental/optional/constexpr/relops/6.cc: Likewise. * testsuite/experimental/optional/make_optional.cc: Likewise. * testsuite/experimental/optional/observers/1.cc: Likewise. * testsuite/experimental/optional/observers/2.cc: Likewise. * testsuite/experimental/optional/observers/3.cc: Likewise. * testsuite/experimental/optional/observers/4.cc: Likewise. * testsuite/experimental/optional/observers/5.cc: Likewise. * testsuite/experimental/optional/relops/1.cc: Likewise. * testsuite/experimental/optional/relops/2.cc: Likewise. * testsuite/experimental/optional/relops/3.cc: Likewise. * testsuite/experimental/optional/relops/4.cc: Likewise. * testsuite/experimental/optional/relops/5.cc: Likewise. * testsuite/experimental/optional/relops/6.cc: Likewise. * testsuite/experimental/optional/requirements.cc: Likewise. * testsuite/experimental/optional/swap/1.cc: Likewise. * testsuite/experimental/optional/typedefs.cc: Likewise. * testsuite/experimental/propagate_const/assignment/move.cc: Likewise. * testsuite/experimental/propagate_const/assignment/move_neg.cc: Likewise. * testsuite/experimental/propagate_const/cons/move.cc: Likewise. * testsuite/experimental/propagate_const/cons/move_neg.cc: Likewise. * testsuite/experimental/propagate_const/hash/1.cc: Likewise. * testsuite/experimental/propagate_const/observers/1.cc: Likewise. * testsuite/experimental/propagate_const/relops/1.cc: Likewise. * testsuite/experimental/propagate_const/requirements1.cc: Likewise. * testsuite/experimental/propagate_const/requirements2.cc: Likewise. * testsuite/experimental/propagate_const/requirements3.cc: Likewise. * testsuite/experimental/propagate_const/requirements4.cc: Likewise. * testsuite/experimental/propagate_const/requirements5.cc: Likewise. * testsuite/experimental/propagate_const/swap/1.cc: Likewise. * testsuite/experimental/propagate_const/typedefs.cc: Likewise. * testsuite/experimental/random/randint.cc: Likewise. * testsuite/experimental/ratio/value.cc: Likewise. * testsuite/experimental/set/erasure.cc: Likewise. * testsuite/experimental/string/erasure.cc: Likewise. * testsuite/experimental/string_view/typedefs.cc: Likewise. * testsuite/experimental/system_error/value.cc: Likewise. * testsuite/experimental/tuple/tuple_size.cc: Likewise. * testsuite/experimental/type_traits/value.cc: Likewise. * testsuite/experimental/unordered_map/erasure.cc: Likewise. * testsuite/experimental/unordered_set/erasure.cc: Likewise. * testsuite/experimental/vector/erasure.cc: Likewise. From-SVN: r242417
2016-11-15 15:33:41 +01:00
// You should have received a copy of the GNU General Public License along
Implement P0032R3, Homogeneous interface for variant, any and optional, for the parts concerning any and optional. * include/std/any (_Storage()): Make constexpr and have it initialize _M_ptr. (any()): Make constexpr. (any(const any&)): Adjust. (any(any&&)): Likewise. (__any_constructible_t): New. (any(_ValueType&&)): Constrain. (any(in_place_type_t<_Tp>, _Args&&...)): New. (any(in_place_type_t<_Tp>, initializer_list<_Up>, _Args&&...)): Likewise. (~any()): Adjust. (operator=(const any&)): Likewise. (operator=(any&&)): Likewise. (operator=(_ValueType&&)): Constrain. (emplace(_Args&&...)): New. (emplace(initializer_list<_Up>, _Args&&...)): Likewise. (clear()): Remove. (reset()): New. (swap(any&)): Adjust. (empty()): Remove. (has_value()): New. (type()): Adjust. (_Manager_internal::_S_create(_Storage&, _Args&&...)): New. (_Manager_external::_S_create(_Storage&, _Args&&...)): Likewise. (make_any(_Args&&...)): Likewise. (make_any(initializer_list<_Up>, _Args&&...)): Likewise. * include/std/optional (in_place_t, in_place): Remove. (bad_optional_access): Add a comment referring to LEWG 72. (emplace(_Args&&...)): Constrain. (has_value()): New. (reset()): Likewise. (make_optional(_Args&&...)): Likewise. (make_optional(initializer_list<_Up>, _Args&&...)): Likewise. * include/std/utility (in_place_tag): New. (__in_place, __in_place_type, __in_place_index): Likewise. (in_place_t, in_place_type_t, in_place_index_t): Likewise. (in_place(__in_place*)): Likewise. (in_place(__in_place_type<_Tp>*)): Likewise. (in_place(__in_place_index<_Idx>*)): Likewise. * testsuite/20_util/any/assign/1.cc: Adjust. * testsuite/20_util/any/assign/emplace.cc: New. * testsuite/20_util/any/assign/self.cc: Adjust. * testsuite/20_util/any/cons/1.cc: Likewise. * testsuite/20_util/any/cons/in_place.cc: New. * testsuite/20_util/any/make_any.cc: Likewise. * testsuite/20_util/any/misc/any_cast_neg.cc: Adjust. * testsuite/20_util/any/misc/swap.cc: Likewise. * testsuite/20_util/any/modifiers/1.cc: Likewise. * testsuite/20_util/any/requirements.cc: New. * testsuite/20_util/in_place/requirements.cc: Likewise. * testsuite/20_util/optional/constexpr/in_place.cc: Adjust. * testsuite/20_util/optional/in_place.cc: Likewise. * testsuite/20_util/optional/make_optional.cc: Add tests for the new overloads of make_optional. From-SVN: r238329
2016-07-14 11:10:05 +02:00
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <any>
#include <testsuite_hooks.h>
#include <vector>
#include <tuple>
struct combined {
std::vector<int> v;
std::tuple<int, int> t;
template<class... Args>
combined(std::initializer_list<int> il, Args&&... args)
: v(il), t(std::forward<Args>(args)...)
{
}
};
int main()
{
const int i = 42;
auto o = std::make_any<int>(i);
int& i2 = std::any_cast<int&>(o);
VERIFY( i2 == 42 );
VERIFY( &i2 != &i );
auto o2 = std::make_any<std::tuple<int, int>>(1, 2);
std::tuple<int, int>& t = std::any_cast<std::tuple<int, int>&>(o2);
VERIFY( std::get<0>(t) == 1 && std::get<1>(t) == 2);
auto o3 = std::make_any<std::vector<int>>({42, 666});
std::vector<int>& v = std::any_cast<std::vector<int>&>(o3);
VERIFY(v[0] == 42 && v[1] == 666);
auto o4 = std::make_any<combined>({42, 666});
combined& c = std::any_cast<combined&>(o4);
VERIFY(c.v[0] == 42 && c.v[1] == 666
&& std::get<0>(c.t) == 0 && std::get<1>(c.t) == 0 );
auto o5 = std::make_any<combined>({1, 2}, 3, 4);
combined& c2 = std::any_cast<combined&>(o5);
VERIFY(c2.v[0] == 1 && c2.v[1] == 2
&& std::get<0>(c2.t) == 3 && std::get<1>(c2.t) == 4 );
}