File: sort_n_with_buffer.cpp

package info (click to toggle)
range-v3 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,652 kB
  • sloc: cpp: 76,839; xml: 226; sh: 89; python: 34; makefile: 19; perl: 15
file content (49 lines) | stat: -rw-r--r-- 1,566 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/// \file
// Range v3 library
//
//  Copyright Casey Carter 2016
//
//  Use, modification and distribution is subject to the
//  Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <range/v3/algorithm/aux_/sort_n_with_buffer.hpp>
#include <functional>
#include <iostream>
#include <utility>
#include <range/v3/range/primitives.hpp>
#include "../simple_test.hpp"

// BUGBUGBUG
namespace std {
    template<typename F, typename S>
    ostream& operator<<(ostream& os, std::pair<F, S> const& p)
    {
        return os << '{' << p.first << ", " << p.second << '}';
    }
}

int main()
{
    std::pair<int, int> some_pairs[] = {
        {0, 3}, {1, 2}, {2, 1}, {3, 0}
    };
    std::pair<int, int> space[2];

    ranges::aux::sort_n_with_buffer(some_pairs + 0, ranges::size(some_pairs), space + 0, std::less<int>{}, &std::pair<int, int>::second);
    CHECK(some_pairs[0] == std::make_pair(3, 0));
    CHECK(some_pairs[1] == std::make_pair(2, 1));
    CHECK(some_pairs[2] == std::make_pair(1, 2));
    CHECK(some_pairs[3] == std::make_pair(0, 3));

    ranges::aux::sort_n_with_buffer(some_pairs + 0, ranges::size(some_pairs), space + 0, std::less<int>{}, &std::pair<int, int>::first);
    CHECK(some_pairs[0] == std::make_pair(0, 3));
    CHECK(some_pairs[1] == std::make_pair(1, 2));
    CHECK(some_pairs[2] == std::make_pair(2, 1));
    CHECK(some_pairs[3] == std::make_pair(3, 0));

    return ::test_result();
}