C++: support variadic emplace

Suggested by Askar Safin.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00006.html

* data/variant.hh: Implement.
* tests/types.at: Check.
* doc/bison.texi: Document.
This commit is contained in:
Akim Demaille
2018-12-10 17:41:24 +01:00
parent d657da9fb4
commit 81dbd0d82e
4 changed files with 42 additions and 28 deletions

View File

@@ -288,21 +288,22 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
AT_VAL.build (std::make_pair<std::string, std::string> ("two", "deux"));],
[10:11, two:deux])
# Move-only types.
# Move-only types, and variadic emplace.
AT_TEST([%skeleton "]b4_skel["
%code requires { #include <memory> }
%define api.value.type variant],
[[%token <std::unique_ptr<int>> '1';
%token <std::unique_ptr<std::string>> '2';]],
['1' '2' { std::cout << *$1 << ", " << *$2 << '\n'; }],
%token <std::pair<int, int>> '2';]],
['1' '2' { std::cout << *$1 << ", "
<< $2.first << ", "
<< $2.second << '\n'; }],
["12"],
[[if (res == '1')
]AT_VAL[.emplace <std::unique_ptr<int>>
(std::make_unique <int> (10));
else if (res == '2')
]AT_VAL[.emplace <std::unique_ptr<std::string>>
(std::make_unique <std::string> ("two"));]],
[10, two],
]AT_VAL[.emplace <std::pair<int, int>> (21, 22);]],
[10, 21, 22],
[AT_REQUIRE_CXX_STD(14, [echo "$at_std not supported"; continue])])])
])
])