1212
1313// class map
1414
15- // insert_return_type insert(node_type&&);
15+ // constexpr insert_return_type insert(node_type&&); // constexpr since C++26
1616
1717#include < map>
1818#include < memory>
2121#include " min_allocator.h"
2222
2323template <class Container , class T >
24- void verify_insert_return_type (T&& t) {
24+ TEST_CONSTEXPR_CXX26 void verify_insert_return_type (T&& t) {
2525 using verified_type = std::remove_cv_t <std::remove_reference_t <T>>;
2626 static_assert (std::is_aggregate_v<verified_type>);
2727 static_assert (std::is_same_v<verified_type, typename Container::insert_return_type>);
@@ -42,20 +42,20 @@ void verify_insert_return_type(T&& t) {
4242}
4343
4444template <class Container >
45- typename Container::node_type
45+ TEST_CONSTEXPR_CXX26 std::pair<Container, typename Container::node_type>
4646node_factory (typename Container::key_type const & key, typename Container::mapped_type const & mapped) {
47- static Container c;
47+ Container c;
4848 auto p = c.insert ({key, mapped});
4949 assert (p.second );
50- return c .extract (p.first );
50+ return {c, c .extract (p.first )} ;
5151}
5252
5353template <class Container >
54- TEST_CONSTEXPR_CXX26 bool test (Container& c) {
54+ TEST_CONSTEXPR_CXX26 void testContainer (Container& c) {
5555 auto * nf = &node_factory<Container>;
5656
5757 for (int i = 0 ; i != 10 ; ++i) {
58- typename Container::node_type node = nf (i, i + 1 );
58+ auto [ /* Container */ staticContainer, /* typename Container::node_type*/ node] = nf (i, i + 1 );
5959 assert (!node.empty ());
6060 typename Container::insert_return_type irt = c.insert (std::move (node));
6161 assert (node.empty ());
@@ -78,13 +78,14 @@ TEST_CONSTEXPR_CXX26 bool test(Container& c) {
7878 }
7979
8080 { // Insert duplicate node.
81- typename Container::node_type dupl = nf (0 , 42 );
81+ auto [ /* Container */ staticContainer, /* typename Container::node_type*/ dupl] = nf (0 , 42 );
8282 auto irt = c.insert (std::move (dupl));
8383 assert (dupl.empty ());
8484 assert (!irt.inserted );
8585 assert (!irt.node .empty ());
8686 assert (irt.position == c.find (0 ));
87- assert (irt.node .key () == 0 && irt.node .mapped () == 42 );
87+ if (!TEST_IS_CONSTANT_EVALUATED)
88+ assert (irt.node .key () == 0 && irt.node .mapped () == 42 );
8889 verify_insert_return_type<Container>(irt);
8990 }
9091
@@ -94,24 +95,21 @@ TEST_CONSTEXPR_CXX26 bool test(Container& c) {
9495 assert (c.count (i) == 1 );
9596 assert (c[i] == i + 1 );
9697 }
98+ }
99+
100+ TEST_CONSTEXPR_CXX26
101+ bool test () {
102+ std::map<int , int > m;
103+ testContainer (m);
104+ std::map<int , int , std::less<int >, min_allocator<std::pair<const int , int >>> m2;
105+ testContainer (m2);
97106 return true ;
98107}
99108
100109int main (int , char **) {
101- {
102- std::map<int , int > m;
103- test (m);
104- std::map<int , int , std::less<int >, min_allocator<std::pair<const int , int >>> m2;
105- test (m2);
106- }
107-
110+ test ();
108111#if TEST_STD_VER >= 26
109- {
110- std::map<int , int > m;
111- test (m);
112- std::map<int , int , std::less<int >, min_allocator<std::pair<const int , int >>> m2;
113- test (m2);
114- }
112+ static_assert (test ());
115113#endif
116114
117115 return 0 ;
0 commit comments