| 1 |
// { dg-do run { target c++17 } } |
| 2 |
// { dg-options "-Wno-init-list-lifetime" } |
| 3 |
|
| 4 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 5 |
// |
| 6 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 7 |
// software; you can redistribute it and/or modify it under the |
| 8 |
// terms of the GNU General Public License as published by the |
| 9 |
// Free Software Foundation; either version 3, or (at your option) |
| 10 |
// any later version. |
| 11 |
|
| 12 |
// This library is distributed in the hope that it will be useful, |
| 13 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
// GNU General Public License for more details. |
| 16 |
|
| 17 |
// You should have received a copy of the GNU General Public License along |
| 18 |
// with this library; see the file COPYING3. If not see |
| 19 |
// <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
#include <any> |
| 22 |
#include <utility> |
| 23 |
#include <tuple> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
|
| 26 |
void |
| 27 |
test01() |
| 28 |
{ |
| 29 |
std::any a; |
| 30 |
a.emplace<std::any>(5); |
| 31 |
VERIFY( std::any_cast<int>(std::any_cast<std::any>(a)) == 5 ); |
| 32 |
|
| 33 |
std::any b; |
| 34 |
b.emplace<std::any>({1}); |
| 35 |
(void) std::any_cast<std::initializer_list<int>>(std::any_cast<std::any>(b)); |
| 36 |
} |
| 37 |
|
| 38 |
void |
| 39 |
test02() |
| 40 |
{ |
| 41 |
std::any p; |
| 42 |
p.emplace<std::pair<std::any, std::any>>(1, 1); |
| 43 |
auto pt = std::any_cast<std::pair<std::any, std::any>>(p); |
| 44 |
VERIFY( std::any_cast<int>(pt.first) == 1 ); |
| 45 |
VERIFY( std::any_cast<int>(pt.second) == 1 ); |
| 46 |
|
| 47 |
std::any t; |
| 48 |
t.emplace<std::tuple<std::any>>(1); |
| 49 |
auto tt = std::any_cast<std::tuple<std::any>>(t); |
| 50 |
VERIFY( std::any_cast<int>(std::get<0>(tt)) == 1 ); |
| 51 |
} |
| 52 |
|
| 53 |
int main() |
| 54 |
{ |
| 55 |
test01(); |
| 56 |
test02(); |
| 57 |
} |