Skip to content

Commit 36ce015

Browse files
authored
fix find_last_of when char isn't found (#49)
resolves #48
1 parent d073770 commit 36ce015

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

include/cib/detail/find.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,20 @@ namespace cib::detail {
3232
}
3333
}
3434

35-
return str.size();
35+
return 0;
3636
}
3737

3838
// clang-8 and below don't have constexpr find_last_of on std::string_view
3939
CIB_CONSTEVAL std::string_view::size_type find_last_of(std::string_view str, char c) {
4040
using size_type = std::string_view::size_type;
41-
for (size_type i = str.size() - 1; true; i--) {
41+
size_type match = str.size();
42+
for (size_type i = 0; i < str.size(); i++) {
4243
if (str[i] == c) {
43-
return i;
44+
match = i;
4445
}
4546
}
47+
48+
return match;
4649
}
4750

4851
template<typename Tag>

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_executable(tests
99
callback.cpp
1010
nexus.cpp
1111
detail/ordered_set.cpp
12+
readme_hello_world.cpp
1213
)
1314

1415
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

test/readme_hello_world.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <cib/cib.hpp>
2+
3+
#include <catch2/catch_test_macros.hpp>
4+
5+
#include <cstdio>
6+
7+
struct say_message : public cib::callback_meta<>{};
8+
9+
// the 'core' component exposes the 'say_message' service for others to extend
10+
struct core {
11+
constexpr static auto config = cib::exports<say_message>;
12+
};
13+
14+
// the 'say_hello_world' component extends 'say_message' with its own functionality
15+
struct say_hello_world {
16+
constexpr static auto config =
17+
cib::extend<say_message>([](){
18+
puts("Hello, world!\n");
19+
});
20+
};
21+
22+
// the 'hello_world' project composes 'core' and 'say_hello_world'
23+
struct hello_world {
24+
constexpr static auto config =
25+
cib::components<core, say_hello_world>;
26+
};
27+
28+
// the nexus instantiates the project
29+
cib::nexus<hello_world> nexus{};
30+
31+
32+
TEST_CASE("make sure the simple hello world example compiles") {
33+
nexus.service<say_message>();
34+
}

0 commit comments

Comments
 (0)