File: test_hash.cpp

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (45 lines) | stat: -rw-r--r-- 1,224 bytes parent folder | download | duplicates (8)
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
//
// Copyright (c) 2018 James E. King III
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//   https://www.boost.org/LICENSE_1_0.txt)
//
// std::hash support for uuid
//

#include <boost/config.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/uuid/string_generator.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_hash.hpp>
#include <iostream>

#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
#include <unordered_set>
#endif

int main(int, char*[])
{
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
    using namespace boost::uuids;
    string_generator gen;

    uuid u1 = gen("01234567-89AB-CDEF-0123-456789abcdef");
    uuid u2 = gen("fedcba98-7654-3210-fedc-ba9876543210");

    std::hash<uuid> hasher;
    BOOST_TEST(hasher(u1) != hasher(u2));

    std::unordered_set<boost::uuids::uuid> uns;
    uns.insert(u1);
    uns.insert(u2);

    BOOST_TEST_EQ(uns.size(), 2);

    return boost::report_errors();
#else
    std::cout << "test skipped - no library support for std::hash or std::unordered_set" << std::endl;
    return 0;
#endif
}