llvm-project
47 строк · 1.4 Кб
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <map>
10
11// class value_compare
12
13// bool operator()( const value_type& lhs, const value_type& rhs ) const;
14
15#include <map>16#include <cassert>17#include <string>18#include <utility>19
20template <typename MMap>21struct CallCompMember : MMap::value_compare {22CallCompMember(const typename MMap::value_compare& vc) : MMap::value_compare(vc) {}23
24typedef typename MMap::value_type value_type;25bool operator()(const value_type& value1, const value_type& value2) const {26return this->comp(value1.first, value2.first);27}28};29
30int main(int, char**) {31typedef std::multimap<int, std::string> map_type;32
33map_type m;34map_type::iterator i1 = m.insert(map_type::value_type(1, "abc"));35map_type::iterator i2 = m.insert(map_type::value_type(2, "abc"));36
37const map_type::value_compare vc = m.value_comp();38CallCompMember<map_type> call_comp = m.value_comp();39
40assert(vc(*i1, *i2));41assert(call_comp(*i1, *i2));42
43assert(!vc(*i2, *i1));44assert(!call_comp(*i2, *i1));45
46return 0;47}
48