Skip to content

Commit f732ef8

Browse files
authored
Merge pull request #106 from os12/master
string_view: corrected the comparison
2 parents fb4830f + 236825f commit f732ef8

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ set(CMAKE_VERBOSE_MAKEFILE true)
1919

2020
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
2121
INCLUDE(CheckCXXCompilerFlag)
22-
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
22+
CHECK_CXX_COMPILER_FLAG(-std=c++14 HAVE_STD11)
2323

2424
if (HAVE_STD11)
25-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
25+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
2626
else()
27-
message(FATAL_ERROR "No C++ 11 support (Compiler does not define -std=c++11).")
27+
message(FATAL_ERROR "No C++ 11 support (Compiler does not define -std=c++14).")
2828
endif()
2929

3030
if (Uri_FULL_WARNINGS)
@@ -37,7 +37,7 @@ if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
3737

3838
message("C++ Flags: ${CMAKE_CXX_FLAGS} link flags: ${CMAKE_CXX_LINK_FLAGS}")
3939
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
40-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
40+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
4141

4242
if (NOT Uri_DISABLE_LIBCXX)
4343
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")

include/network/string_view.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ class basic_string_view {
161161
}
162162

163163
constexpr int compare(basic_string_view s) const noexcept {
164-
return traits::compare(data(), s.data(), std::min(size(), s.size()));
164+
if (size() != s.size())
165+
return size() < s.size() ? -1 : 1;
166+
return traits::compare(data(), s.data(), size());
165167
}
166168

167169
constexpr int compare(size_type pos1, size_type n1,

src/boost/function/function_base.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ namespace network_boost {
308308
if (op == clone_functor_tag || op == move_functor_tag) {
309309
const functor_type* in_functor =
310310
reinterpret_cast<const functor_type*>(&in_buffer.data);
311-
new (reinterpret_cast<void*>(&out_buffer.data)) functor_type(*in_functor);
311+
void *address = &out_buffer.data;
312+
new (address) functor_type(*in_functor);
312313

313314
if (op == move_functor_tag) {
314315
functor_type* f = reinterpret_cast<functor_type*>(&in_buffer.data);

src/boost/function/function_template.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ namespace network_boost {
569569
void
570570
assign_functor(FunctionObj f, function_buffer& functor, mpl::true_) const
571571
{
572-
new (reinterpret_cast<void*>(&functor.data)) FunctionObj(f);
572+
void *address = &functor.data;
573+
new (address) FunctionObj(f);
573574
}
574575
template<typename FunctionObj,typename Allocator>
575576
void

src/uri.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ void uri::initialize(optional<string_type> scheme,
166166
}
167167
}
168168

169-
uri::uri() : uri_view_(uri_), uri_parts_() {}
169+
uri::uri() : uri_view_(uri_) {}
170170

171-
uri::uri(const uri &other) : uri_(other.uri_), uri_view_(uri_), uri_parts_() {
171+
uri::uri(const uri &other) : uri_(other.uri_), uri_view_(uri_) {
172172
detail::advance_parts(uri_view_, uri_parts_, other.uri_parts_);
173173
}
174174

175-
uri::uri(const uri_builder &builder) : uri_parts_() {
175+
uri::uri(const uri_builder &builder) {
176176
initialize(builder.scheme_, builder.user_info_, builder.host_, builder.port_,
177177
builder.path_, builder.query_, builder.fragment_);
178178
}
@@ -194,11 +194,12 @@ uri &uri::operator=(uri other) {
194194
}
195195

196196
void uri::swap(uri &other) noexcept {
197-
auto parts = uri_parts_;
198-
advance_parts(other.uri_view_, uri_parts_, other.uri_parts_);
199197
uri_.swap(other.uri_);
200198
uri_view_.swap(other.uri_view_);
201-
advance_parts(other.uri_view_, other.uri_parts_, parts);
199+
200+
const auto this_parts = uri_parts_;
201+
detail::advance_parts(uri_view_, uri_parts_, other.uri_parts_);
202+
detail::advance_parts(other.uri_view_, other.uri_parts_, this_parts);
202203
}
203204

204205
uri::const_iterator uri::begin() const noexcept { return uri_view_.begin(); }

test/uri_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ TEST(uri_test, swap_test) {
444444
ASSERT_TRUE(original.has_path());
445445
EXPECT_EQ("file", original.scheme());
446446
EXPECT_EQ("", original.host());
447-
EXPECT_EQ("/something/different", original.path());
447+
EXPECT_EQ("/something/different/", original.path());
448448

449449
ASSERT_TRUE(instance.has_scheme());
450450
ASSERT_TRUE(instance.has_host());

0 commit comments

Comments
 (0)