From 6f26572aaea692fc44632274f08c9e316f7eaf93 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Sun, 29 Mar 2026 19:50:05 +0200 Subject: [PATCH] tested and documented std::initializer_list ctor --- doc/reference/bimap.qbk | 6 ++++ doc/release_notes.qbk | 4 +++ test/test_bimap.hpp | 56 +++++++++++++++++++++++++++++++---- test/test_bimap_ordered.cpp | 4 ++- test/test_bimap_unordered.cpp | 3 +- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/doc/reference/bimap.qbk b/doc/reference/bimap.qbk index 737a1106..0df1b2bd 100644 --- a/doc/reference/bimap.qbk +++ b/doc/reference/bimap.qbk @@ -171,6 +171,8 @@ this tags. template< class InputIterator > bimap(InputIterator first,InputIterator last); + bimap(std::initializer_list init); + bimap(const bimap &); bimap& operator=(const bimap& b); @@ -344,6 +346,10 @@ acceptance by the collection types of the `bimap`. * [link complexity_signature_explanation [*Complexity:]] O(m*H(m)), where m is the number of elements in `[first,last)`. + bimap(std::initializer_list init); + +* [*Effects:] Equivalent to `bimap(init.begin(), init.end())`. +* [*Complexity:] O(init.size()*H(init.size())). bimap(const bimap & x); diff --git a/doc/release_notes.qbk b/doc/release_notes.qbk index 8f983da0..acf20a7e 100644 --- a/doc/release_notes.qbk +++ b/doc/release_notes.qbk @@ -14,6 +14,10 @@ http://www.boost.org/LICENSE_1_0.txt) [section Release notes] +[heading Boost 1.92 release] + +* Added `std::initializer_list` constructor ([@https://github.com/boostorg/bimap/pull/31 PR#31]). + [heading Boost 1.91 release] * Adapted the library to work with the latest updates of Boost.MultiIndex ([@https://github.com/boostorg/bimap/pull/49 PR#49]). diff --git a/test/test_bimap.hpp b/test/test_bimap.hpp index a64ce4fb..233b5760 100644 --- a/test/test_bimap.hpp +++ b/test/test_bimap.hpp @@ -1,7 +1,7 @@ // Boost.Bimap // // Copyright (c) 2006-2007 Matias Capeletto -// Copyright (c) 2024 Joaquin M Lopez Munoz +// Copyright (c) 2024-2026 Joaquin M Lopez Munoz // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -20,9 +20,11 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -637,24 +639,66 @@ void test_unordered_set_unordered_multiset_bimap(Bimap & b, test_unique_container(b.right, rd); } +template< class Bimap, class Data > +std::vector make_value_type_vector( + const Data& d, std::size_t n) +{ + std::vector res; + auto first = d.begin(), last = d.end(); + while(n--) { + res.push_back(std::next(first) == last? *first: *++first); + } + return res; +} + +template< class Bimap > +bool check_equal(const Bimap& b1, const Bimap& b2, boost::true_type) +{ + return b1 == b2; +} + +template< class Bimap > +bool check_equal(const Bimap& b1, const Bimap& b2, boost::false_type) +{ + if(b1.size() != b2.size()) return false; + for(const auto& x: b1) { + if(std::find(b2.begin(), b2.end(), x) == b2.end()) return false; + } + for(const auto& x: b2) { + if(std::find(b1.begin(), b1.end(), x) == b1.end()) return false; + } + return true; +} + +template< class Bimap > +bool check_equal(const Bimap& b1, const Bimap& b2) +{ + return check_equal(b1, b2, boost::has_equal_to{}); +} + template< class Bimap, class Data> void test_bimap_init_copy_swap(const Data&d) { Bimap b1(d.begin(),d.end()); Bimap b2( b1 ); - BOOST_TEST( b1 == b2 ); - + BOOST_TEST( check_equal(b1, b2) ); + + auto v = make_value_type_vector(d, 5); + Bimap b3({v[0], v[1], v[2], v[3], v[4]}); + Bimap b4(v.begin(), v.end()); + BOOST_TEST( check_equal(b3, b4) ); + b2.clear(); b2 = b1; - BOOST_TEST( b2 == b1 ); + BOOST_TEST( check_equal(b2, b1) ); b2.clear(); b2.left = b1.left; - BOOST_TEST( b2 == b1 ); + BOOST_TEST( check_equal(b2, b1) ); b2.clear(); b2.right = b1.right; - BOOST_TEST( b2 == b1 ); + BOOST_TEST( check_equal(b2, b1) ); b1.clear(); b2.swap(b1); diff --git a/test/test_bimap_ordered.cpp b/test/test_bimap_ordered.cpp index 1e242ab4..fe55df0e 100644 --- a/test/test_bimap_ordered.cpp +++ b/test/test_bimap_ordered.cpp @@ -1,7 +1,7 @@ // Boost.Bimap // // Copyright (c) 2006-2007 Matias Capeletto -// Copyright (c) 2024 Joaquin M Lopez Munoz +// Copyright (c) 2024-2026 Joaquin M Lopez Munoz // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -74,6 +74,8 @@ void test_bimap() data.insert( bm_type::value_type(4,0.4) ); bm_type bm; + + test_bimap_init_copy_swap(data) ; test_set_set_bimap(bm,data,left_data,right_data); } //-------------------------------------------------------------------- diff --git a/test/test_bimap_unordered.cpp b/test/test_bimap_unordered.cpp index 32c97011..7fd8e76a 100644 --- a/test/test_bimap_unordered.cpp +++ b/test/test_bimap_unordered.cpp @@ -1,7 +1,7 @@ // Boost.Bimap // // Copyright (c) 2006-2007 Matias Capeletto -// Copyright (c) 2024 Joaquin M Lopez Munoz +// Copyright (c) 2024-2026 Joaquin M Lopez Munoz // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -77,6 +77,7 @@ void test_bimap() bm_type bm; + test_bimap_init_copy_swap(data) ; test_unordered_set_unordered_multiset_bimap( bm,data,left_data,right_data );