File: doc_types.hpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (114 lines) | stat: -rw-r--r-- 2,052 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Copyright (c) 2022 Dmitry Arkhipov (grisumbras@yandex.ru)
//
// Distributed under 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)
//
// Official repository: https://github.com/boostorg/json
//


#ifndef BOOST_JSON_DOC_DOC_TYPES_HPP
#define BOOST_JSON_DOC_DOC_TYPES_HPP

#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wmismatched-tags"
#endif

#include <array>

// tag::snippet_conv_spec_trait1[]
namespace user_ns
{

class ip_address
{
public:
    ip_address(
        unsigned char oct1,
        unsigned char oct2,
        unsigned char oct3,
        unsigned char oct4 );

    const unsigned char*
    begin() const;

    const unsigned char*
    end() const;

private:
    std::array<unsigned char, 4> octets_;
};

template< std::size_t N >
unsigned char
get(const ip_address& addr);

} // namespace user_ns

namespace std
{

template<>
struct tuple_size< user_ns::ip_address >
    : std::integral_constant<std::size_t, 4>
{ };

template< std::size_t N >
struct tuple_element< N, user_ns::ip_address >
{
    using type = unsigned char;
};

} // namespace std
// end::snippet_conv_spec_trait1[]

namespace user_ns
{

inline
ip_address::ip_address(
    unsigned char oct1,
    unsigned char oct2,
    unsigned char oct3,
    unsigned char oct4 )
    : octets_{{oct1, oct2, oct3, oct4}}
{ }

inline
const unsigned char*
ip_address::begin() const
{
    return octets_.data();
}

inline
const unsigned char*
ip_address::end() const
{
    return begin() + octets_.size();
}

template< std::size_t N >
unsigned char
get(ip_address const& addr )
{
    static_assert( N >= 0 && N <= 4, "incorrect N" );
    return *(addr.begin() + N);
}

inline
bool
operator==(ip_address const& l, ip_address const& r) noexcept
{
    return
        get<0>(l) == get<0>(r) &&
        get<1>(l) == get<1>(r) &&
        get<2>(l) == get<2>(r) &&
        get<3>(l) == get<3>(r);
}

} // namespace user_ns

#endif // BOOST_JSON_DOC_DOC_TYPES_HPP