Skip to content

Commit

Permalink
fix find_last_of when char isn't found (#49)
Browse files Browse the repository at this point in the history
resolves #48
  • Loading branch information
lukevalenty committed Apr 24, 2022
1 parent d073770 commit 36ce015
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/cib/detail/find.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ namespace cib::detail {
}
}

return str.size();
return 0;
}

// clang-8 and below don't have constexpr find_last_of on std::string_view
CIB_CONSTEVAL std::string_view::size_type find_last_of(std::string_view str, char c) {
using size_type = std::string_view::size_type;
for (size_type i = str.size() - 1; true; i--) {
size_type match = str.size();
for (size_type i = 0; i < str.size(); i++) {
if (str[i] == c) {
return i;
match = i;
}
}

return match;
}

template<typename Tag>
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_executable(tests
callback.cpp
nexus.cpp
detail/ordered_set.cpp
readme_hello_world.cpp
)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand Down
34 changes: 34 additions & 0 deletions test/readme_hello_world.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <cib/cib.hpp>

#include <catch2/catch_test_macros.hpp>

#include <cstdio>

struct say_message : public cib::callback_meta<>{};

// the 'core' component exposes the 'say_message' service for others to extend
struct core {
constexpr static auto config = cib::exports<say_message>;
};

// the 'say_hello_world' component extends 'say_message' with its own functionality
struct say_hello_world {
constexpr static auto config =
cib::extend<say_message>([](){
puts("Hello, world!\n");
});
};

// the 'hello_world' project composes 'core' and 'say_hello_world'
struct hello_world {
constexpr static auto config =
cib::components<core, say_hello_world>;
};

// the nexus instantiates the project
cib::nexus<hello_world> nexus{};


TEST_CASE("make sure the simple hello world example compiles") {
nexus.service<say_message>();
}

0 comments on commit 36ce015

Please sign in to comment.