Skip to content

Commit 96f8581

Browse files
committed
Fixes and refactoring
1 parent 6003234 commit 96f8581

File tree

13 files changed

+121
-77
lines changed

13 files changed

+121
-77
lines changed

.drone.star

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
1+
# Use, modification, and distribution are
2+
# subject to the Boost Software License, Version 1.0. (See accompanying
3+
# file LICENSE.txt)
14
#
2-
# Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
3-
#
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)
5+
# Copyright Rene Rivera 2020.
6+
# Copyright Alan de Freitas 2022.
7+
8+
# For Drone CI we use the Starlark scripting language to reduce duplication.
9+
# As the yaml syntax for Drone CI is rather limited.
610
#
7-
# Official repository: https://github.com/CPPAlliance/buffers
811
#
912

1013
def main(ctx):
1114
return generate(
1215
# Compilers
13-
['gcc >=5.0',
14-
'clang >=3.8',
15-
'msvc >=14.1',
16-
'arm64-gcc latest',
17-
's390x-gcc latest',
18-
'apple-clang *',
19-
'arm64-clang latest',
20-
's390x-clang latest',
21-
# 'x86-msvc latest'
22-
],
16+
[
17+
'gcc >=5.0',
18+
'clang >=3.8',
19+
'msvc >=14.1',
20+
'arm64-gcc latest',
21+
's390x-gcc latest',
22+
# 'freebsd-gcc latest',
23+
'apple-clang *',
24+
'arm64-clang latest',
25+
's390x-clang latest',
26+
'freebsd-clang latest',
27+
'x86-msvc latest'
28+
],
2329
# Standards
2430
'>=11',
25-
packages=[])
31+
# Asan is delegated to GHA
32+
asan=False,
33+
docs=False,
34+
cache_dir='cache') + [
35+
linux_cxx("GCC 12 (no-mutex)", "g++-12", packages="g++-12", buildscript="drone", buildtype="boost",
36+
image="cppalliance/droneubuntu2204:1",
37+
environment={'B2_TOOLSET': 'gcc-12', 'B2_DEFINES': 'BOOST_URL_DISABLE_THREADS=1',
38+
'B2_CXXSTD': '17'}, globalenv={'B2_CI_VERSION': '1', 'B2_VARIANT': 'release'}),
39+
]
40+
2641

42+
# from https://github.com/cppalliance/ci-automation
43+
load("@ci_automation//ci/drone/:functions.star", "linux_cxx", "windows_cxx", "osx_cxx", "freebsd_cxx", "generate")
2744

28-
# from https://github.com/boostorg/boost-ci
29-
load("@boost_ci//ci/drone/:functions.star", "linux_cxx", "windows_cxx", "osx_cxx", "freebsd_cxx")
30-
load("@url//:.drone.star", "generate")

include/boost/buffers/front.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
#define BOOST_BUFFERS_FRONT_HPP
1212

1313
#include <boost/buffers/detail/config.hpp>
14+
#include <boost/buffers/const_buffer.hpp>
15+
#include <boost/buffers/mutable_buffer.hpp>
1416
#include <boost/buffers/type_traits.hpp>
17+
#include <type_traits>
1518

1619
namespace boost {
1720
namespace buffers {
1821

19-
namespace detail {
20-
21-
struct front_impl
22+
/** Return the first buffer in a sequence.
23+
*/
24+
constexpr struct
2225
{
2326
template<
2427
class MutableBufferSequence
@@ -56,13 +59,7 @@ struct front_impl
5659
return *it;
5760
return {};
5861
}
59-
};
60-
61-
} // detail
62-
63-
/** Return the first buffer in a sequence.
64-
*/
65-
constexpr detail::front_impl front{};
62+
} const front{};
6663

6764
} // buffers
6865
} // boost

include/boost/buffers/prefix.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ tag_invoke(
4242
Span<T, Extent>
4343
>::type
4444
{
45-
if(n <= bs.size())
46-
return bs.subspan(0, n);
47-
return bs;
45+
return n <= bs.size() ? bs.subspan(0, n) : bs;
4846
}
4947

5048
/** Return the first n bytes of a buffer sequence

include/boost/buffers/sans_prefix.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
namespace boost {
1818
namespace buffers {
1919

20+
/** Return a suffix of the buffer sequence.
21+
*/
2022
constexpr struct
2123
{
2224
template<class T>
@@ -25,11 +27,19 @@ constexpr struct
2527
std::size_t n) const ->
2628
suffix_type<T>
2729
{
28-
auto const n0 = size(bs);
29-
if(n < n0)
30-
return suffix(bs, n0 - n);
31-
return suffix(bs, 0);
30+
return invoke(bs, n, size(bs));
3231
}
32+
33+
private:
34+
template<class T>
35+
constexpr auto invoke(
36+
T const& bs,
37+
std::size_t n,
38+
std::size_t n0) const ->
39+
suffix_type<T>
40+
{
41+
return suffix(bs, (n < n0) ? n0 - n : 0);
42+
}
3343
} const sans_prefix{};
3444

3545
} // buffers

include/boost/buffers/sans_suffix.hpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,35 @@
1212

1313
#include <boost/buffers/detail/config.hpp>
1414
#include <boost/buffers/size.hpp>
15-
#include <boost/buffers/const_buffer.hpp>
16-
#include <boost/buffers/mutable_buffer.hpp>
17-
#include <boost/buffers/range.hpp>
18-
#include <boost/buffers/tag_invoke.hpp>
19-
#include <boost/buffers/type_traits.hpp>
20-
2115
#include <boost/buffers/prefix.hpp>
22-
#include <boost/buffers/suffix.hpp>
2316

2417
namespace boost {
2518
namespace buffers {
2619

27-
namespace detail {
28-
29-
struct sans_suffix_impl
20+
/** Return a prefix of the buffer sequence.
21+
*/
22+
constexpr struct
3023
{
31-
template<class BufferSequence>
32-
prefix_type<BufferSequence>
33-
operator()(
34-
BufferSequence const& b,
35-
std::size_t n) const
24+
template<class T>
25+
constexpr auto operator()(
26+
T const& bs,
27+
std::size_t n) const ->
28+
prefix_type<T>
3629
{
37-
auto const n0 = size(b);
38-
if(n < n0)
39-
return prefix(b, n0 - n);
40-
return prefix(b, 0);
30+
return invoke(bs, n, size(bs));
4131
}
42-
};
43-
44-
} // detail
4532

46-
/** Return a prefix of the buffer sequence.
47-
*/
48-
constexpr detail::sans_suffix_impl sans_suffix{};
33+
private:
34+
template<class T>
35+
constexpr auto invoke(
36+
T const& bs,
37+
std::size_t n,
38+
std::size_t n0) const ->
39+
prefix_type<T>
40+
{
41+
return prefix(bs, (n < n0) ? n0 - n : 0);
42+
}
43+
} const sans_suffix{};
4944

5045
} // buffers
5146
} // boost

include/boost/buffers/suffix.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ tag_invoke(
4242
Span<T, Extent>
4343
>::type
4444
{
45-
if(n < bs.size())
46-
return bs.subspan(bs.size() - n);
47-
return bs;
45+
return n < bs.size() ?
46+
bs.subspan(bs.size() - n) : bs;
4847
}
4948

5049
/** Return the last n bytes of a buffer sequence

test/unit/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,30 @@ set(EXTRAFILES
1313
)
1414

1515
set(PFILES
16+
test_helpers.hpp
1617
CMakeLists.txt
1718
Jamfile
18-
test_helpers.hpp
1919
any_dynamic_buffer.cpp
2020
asio.cpp
21-
copy.cpp
22-
size.cpp
2321
buffers.cpp
2422
circular_buffer.cpp
2523
const_buffer.cpp
2624
const_buffer_pair.cpp
2725
const_buffer_span.cpp
2826
const_buffer_subspan.cpp
27+
copy.cpp
2928
flat_buffer.cpp
30-
# front.cpp
29+
front.cpp
3130
make_buffer.cpp
3231
mutable_buffer.cpp
3332
mutable_buffer_pair.cpp
3433
mutable_buffer_span.cpp
3534
mutable_buffer_subspan.cpp
3635
prefix.cpp
3736
range.cpp
37+
sans_prefix.cpp
38+
sans_suffix.cpp
39+
size.cpp
3840
string_buffer.cpp
3941
suffix.cpp
4042
tag_invoke.cpp

test/unit/Jamfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ local SOURCES =
2323
test_helpers.hpp
2424
any_dynamic_buffer.cpp
2525
asio.cpp
26-
copy.cpp
27-
size.cpp
2826
buffers.cpp
2927
circular_buffer.cpp
3028
const_buffer.cpp
3129
const_buffer_pair.cpp
3230
const_buffer_span.cpp
3331
const_buffer_subspan.cpp
32+
copy.cpp
3433
flat_buffer.cpp
35-
# front.cpp
34+
front.cpp
3635
make_buffer.cpp
3736
mutable_buffer.cpp
3837
mutable_buffer_pair.cpp
3938
mutable_buffer_span.cpp
4039
mutable_buffer_subspan.cpp
4140
prefix.cpp
4241
range.cpp
42+
sans_prefix.cpp
43+
sans_suffix.cpp
44+
size.cpp
4345
string_buffer.cpp
4446
suffix.cpp
4547
tag_invoke.cpp

test/unit/buffers.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,23 @@
99

1010
// Test that header file is self-contained.
1111
#include <boost/buffers.hpp>
12+
13+
/*
14+
15+
BufferSequence
16+
Type Traits
17+
is_const_buffer_sequence
18+
(mutable sequences are also const sequences?)
19+
is_mutable_buffer_sequence
20+
Algorithms
21+
begin
22+
empty
23+
end
24+
front
25+
size
26+
prefix
27+
sans_prefix
28+
sans_suffix
29+
suffix
30+
31+
*/

test/unit/const_buffer.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ struct const_buffer_test
2222
{
2323
// const_buffer()
2424
BOOST_TEST_EQ(const_buffer().size(), 0);
25+
BOOST_TEST_EQ(const_buffer().data(), nullptr);
2526

2627
// const_buffer(void const*, size_t)
2728
{
28-
auto p = "12345";
29+
char const* p = "12345";
2930
const_buffer b( p, 5 );
3031
BOOST_TEST_EQ(b.data(), p);
3132
BOOST_TEST_EQ(b.size(), 5);
3233
}
3334

3435
// const_buffer(const_buffer)
3536
{
36-
auto p = "12345";
37+
char const* p = "12345";
3738
const_buffer b0( p, 5 );
3839
const_buffer b(b0);
3940
BOOST_TEST_EQ(b.data(), p);
@@ -51,15 +52,12 @@ struct const_buffer_test
5152

5253
// operator=(const_buffer)
5354
{
54-
auto p = "12345";
55+
char const* p = "12345";
5556
const_buffer b;
5657
b = const_buffer(p, 5);
5758
BOOST_TEST_EQ(b.data(), p);
5859
BOOST_TEST_EQ(b.size(), 5);
5960
}
60-
61-
// VFALCO TODO test algorithms:
62-
// prefix, suffix, sans_prefix, sans_suffix
6361
}
6462

6563
void

0 commit comments

Comments
 (0)