• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #848

07 Dec 2022 11:00PM CUT coverage: 86.456% (+0.6%) from 85.835%
#848

push

StellarBot
Merge #6096

6096: Forking Boost.Tokenizer r=hkaiser a=hkaiser

- flyby: remove more Boost headers that are not needed anymore

Working towards #3440 

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

525 of 525 new or added lines in 20 files covered. (100.0%)

173087 of 200202 relevant lines covered (86.46%)

1845223.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.88
/libs/core/string_util/include/hpx/string_util/token_iterator.hpp
1
//  Copyright (c) 2022 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
// Copyright John R. Bandela 2001
8

9
// See http://www.boost.org/libs/tokenizer for documentation.
10

11
// Revision History:
12
// 16 Jul 2003   John Bandela
13
//      Allowed conversions from convertible base iterators
14
// 03 Jul 2003   John Bandela
15
//      Converted to new iterator adapter
16

17
#pragma once
18

19
#include <hpx/config.hpp>
20
#include <hpx/assert.hpp>
21
#include <hpx/iterator_support/detail/minimum_category.hpp>
22
#include <hpx/iterator_support/iterator_adaptor.hpp>
23
#include <hpx/iterator_support/iterator_facade.hpp>
24
#include <hpx/string_util/token_functions.hpp>
25

26
#include <string>
27
#include <type_traits>
28
#include <utility>
29

30
namespace hpx::string_util {
31

32
    template <typename TokenizerFunc, typename Iterator, typename Type>
33
    class token_iterator
142,884✔
34
      : public util::iterator_facade<
35
            token_iterator<TokenizerFunc, Iterator, Type>, Type,
36
            typename util::detail::minimum_category<std::forward_iterator_tag,
37
                typename std::iterator_traits<Iterator>::iterator_category>::
38
                type,
39
            Type const&>
40
    {
41
    private:
42
        friend class util::iterator_core_access;
43

44
        TokenizerFunc f_;
45
        Iterator begin_;
46
        Iterator end_;
47
        bool valid_ = false;
142,747✔
48
        Type tok_;
49

50
        void increment()
65,087✔
51
        {
52
            HPX_ASSERT(valid_);
65,087✔
53
            valid_ = f_(begin_, end_, tok_);
65,087✔
54
        }
65,087✔
55

56
        Type const& dereference() const noexcept
92,391✔
57
        {
58
            HPX_ASSERT(valid_);
92,391✔
59
            return tok_;
92,391✔
60
        }
61

62
        template <typename Other>
63
        bool equal(Other const& a) const noexcept
130,250✔
64
        {
65
            return (a.valid_ && valid_) ?
137,779✔
66
                ((a.begin_ == begin_) && (a.end_ == end_)) :
7,529✔
67
                (a.valid_ == valid_);
122,721✔
68
        }
69

70
        void initialize()
142,742✔
71
        {
72
            if (valid_)
142,742✔
73
                return;
×
74

75
            f_.reset();
142,742✔
76
            valid_ = (begin_ != end_) ? f_(begin_, end_, tok_) : false;
142,742✔
77
        }
142,742✔
78

79
    public:
80
        token_iterator() = default;
5✔
81

82
        template <typename F>
83
        token_iterator(F&& f, Iterator begin, Iterator e = Iterator())
142,742✔
84
          : f_(HPX_FORWARD(F, f))
142,742✔
85
          , begin_(begin)
142,742✔
86
          , end_(e)
142,742✔
87
          , tok_()
142,742✔
88
        {
142,742✔
89
            initialize();
142,742✔
90
        }
142,742✔
91

92
        explicit token_iterator(Iterator begin, Iterator e = Iterator())
93
          : f_()
94
          , begin_(begin)
95
          , end_(e)
96
          , tok_()
97
        {
98
            initialize();
99
        }
100

101
        template <typename OtherIter,
102
            typename =
103
                std::enable_if_t<std::is_convertible_v<OtherIter, Iterator>>>
104
        explicit token_iterator(
105
            token_iterator<TokenizerFunc, OtherIter, Type> const& t)
106
          : f_(t.tokenizer_function())
107
          , begin_(t.base())
108
          , end_(t.end())
109
          , valid_(!t.at_end())
110
          , tok_(t.current_token())
111
        {
112
        }
113

114
        Iterator base() const
115
        {
116
            return begin_;
117
        }
118

119
        Iterator end() const
120
        {
121
            return end_;
122
        }
123

124
        TokenizerFunc const& tokenizer_function() const noexcept
125
        {
126
            return f_;
127
        }
128

129
        Type current_token() const
130
        {
131
            return tok_;
132
        }
133

134
        bool at_end() const noexcept
5✔
135
        {
136
            return !valid_;
5✔
137
        }
138
    };
139

140
    template <typename TokenizerFunc = char_separator<char>,
141
        typename Iterator = std::string::const_iterator,
142
        typename Type = std::string>
143
    struct token_iterator_generator
144
    {
145
        using type = token_iterator<TokenizerFunc, Iterator, Type>;
146
    };
147

148
    // Type has to be first because it needs to be explicitly specified as there
149
    // is no way the function can deduce it.
150
    template <typename Type, typename Iterator, typename TokenizerFunc>
151
    typename token_iterator_generator<std::decay_t<TokenizerFunc>, Iterator,
152
        Type>::type
153
    make_token_iterator(Iterator begin, Iterator end, TokenizerFunc&& fun)
8✔
154
    {
155
        using iterator_type =
156
            typename token_iterator_generator<std::decay_t<TokenizerFunc>,
157
                Iterator, Type>::type;
158
        return iterator_type(HPX_FORWARD(TokenizerFunc, fun), begin, end);
8✔
159
    }
160
}    // namespace hpx::string_util
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc