Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ repos:
- repo: https://github.com/bemanproject/beman-tidy
rev: v0.3.1
hooks:
- id: beman-tidy
- id: beman-tidy
args: [".", "--verbose", "--require-all"]
Copy link
Copy Markdown
Member

@neatudarius neatudarius Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peter (@dascandy ), would you like to apply all RECOMMENDATIONS (actually only one left) and enabled --require-all in beman-tidy CI?

Context: During today's hackathon, as discussed in the meeting last Monday (and announced on discourse - https://discourse.bemanproject.org/t/heads-up-bemanification-event-saturday-april-25/575/2), we enabled beman-tidy in default mode on CI (it only checks for requirements; NOT recommendations).

My advice is to enabled --require-all, but as discussed with @bemanproject/project-leads , final decision is at library owners.

LE Also left similar suggestion on attached issue bemanproject/beman-tidy#252 (comment)


exclude: 'cookiecutter/|infra/'
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The following code snippet illustrates how we can use `cstring_view` to make a b
#include <beman/cstring_view/cstring_view.hpp>
#include <vector>

using namespace beman::cstring_view;

int main(int argc, const char** argv) {
std::vector<cstring_view> args(argv, argv+argc);
}
Expand Down
22 changes: 11 additions & 11 deletions examples/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string_view>

using namespace std::literals;
using namespace beman::literals;
using namespace beman::cstring_view::literals;

#if __cpp_lib_three_way_comparison
std::string_view to_string(std::strong_ordering order) {
Expand All @@ -27,18 +27,18 @@ std::string_view to_string(std::strong_ordering order) {
#endif

int main() {
std::string s = "hello world";
beman::cstring_view z0 = "hello";
beman::cstring_view z1 = s;
beman::cstring_view empty;
std::string s = "hello world";
beman::cstring_view::cstring_view z0 = "hello";
beman::cstring_view::cstring_view z1 = s;
beman::cstring_view::cstring_view empty;
std::cout << z0 << "\n";
#if __cpp_lib_starts_ends_with >= 201711L
std::cout << s.starts_with(z0) << "\n";
std::cout << z0.starts_with(s) << "\n";
std::cout << z0.starts_with("hello") << "\n";
std::cout << z0.starts_with("hello"_csv) << "\n";
#endif
std::cout << std::hash<beman::cstring_view>{}(z1) << "\n";
std::cout << std::hash<beman::cstring_view::cstring_view>{}(z1) << "\n";
std::cout << z1 << std::endl;
std::cout << ("hello"_csv == "hello"sv) << "\n";
std::cout << ("hello"_csv == "hello"_csv) << "\n";
Expand All @@ -53,10 +53,10 @@ int main() {
std::cout << "\"" << empty << "\"\n";
std::cout << (empty == ""_csv) << "\n";

std::wstring ws = L"hello world";
beman::wcstring_view wz0 = L"hello";
beman::wcstring_view wz1 = ws;
beman::wcstring_view wempty;
std::wstring ws = L"hello world";
beman::cstring_view::wcstring_view wz0 = L"hello";
beman::cstring_view::wcstring_view wz1 = ws;
beman::cstring_view::wcstring_view wempty;
#if __cpp_lib_format >= 201907L
std::wcout << std::format(L"{}\n", wz0);
#endif
Expand All @@ -66,7 +66,7 @@ int main() {
std::cout << wz0.starts_with(L"hello") << "\n";
std::cout << wz0.starts_with(L"hello"_csv) << "\n";
#endif
std::cout << std::hash<beman::wcstring_view>{}(wz1) << "\n";
std::cout << std::hash<beman::cstring_view::wcstring_view>{}(wz1) << "\n";
std::wcout << wz1 << std::endl;
std::cout << (L"hello"_csv == L"hello"sv) << "\n";
std::cout << (L"hello"_csv == L"hello"_csv) << "\n";
Expand Down
96 changes: 57 additions & 39 deletions include/beman/cstring_view/cstring_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string>

namespace beman {
namespace cstring_view {

#if !defined(USE_CPP17_VARIANT)
static_assert(__cpp_concepts >= 201907L);
Expand Down Expand Up @@ -53,7 +54,10 @@ using u16cstring_view = basic_cstring_view<char16_t>;
using u32cstring_view = basic_cstring_view<char32_t>;
using wcstring_view = basic_cstring_view<wchar_t>;

inline namespace literals {
} // namespace cstring_view
} // namespace beman

namespace beman::cstring_view::literals {
inline namespace cstring_view_literals {
#ifndef _MSC_VER
#pragma GCC diagnostic push
Expand All @@ -67,23 +71,23 @@ inline namespace cstring_view_literals {
#pragma warning(disable : 4455)
#endif
// [cstring.view.literals], suffix for basic_cstring_view literals
constexpr cstring_view operator""_csv(const char* str, size_t len) noexcept;
constexpr beman::cstring_view::cstring_view operator""_csv(const char* str, size_t len) noexcept;
#if __cpp_char8_t >= 201811L
constexpr u8cstring_view operator""_csv(const char8_t* str, size_t len) noexcept;
constexpr beman::cstring_view::u8cstring_view operator""_csv(const char8_t* str, size_t len) noexcept;
#endif
constexpr u16cstring_view operator""_csv(const char16_t* str, size_t len) noexcept;
constexpr u32cstring_view operator""_csv(const char32_t* str, size_t len) noexcept;
constexpr wcstring_view operator""_csv(const wchar_t* str, size_t len) noexcept;
constexpr beman::cstring_view::u16cstring_view operator""_csv(const char16_t* str, size_t len) noexcept;
constexpr beman::cstring_view::u32cstring_view operator""_csv(const char32_t* str, size_t len) noexcept;
constexpr beman::cstring_view::wcstring_view operator""_csv(const wchar_t* str, size_t len) noexcept;
#ifndef _MSC_VER
#pragma GCC diagnostic pop
#else
#pragma warning(pop)
#endif
} // namespace cstring_view_literals
} // namespace literals
} // namespace beman
} // namespace beman::cstring_view::literals

namespace beman {
namespace cstring_view {

template <class charT, class traits /* = char_traits<charT> */>
class basic_cstring_view {
Expand Down Expand Up @@ -351,43 +355,47 @@ class basic_cstring_view {
size_type size_; // exposition only
};

inline namespace literals {
template <class charT, class traits>
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os,
basic_cstring_view<charT, traits> str) {
return os << std::basic_string_view<charT, traits>(str);
}

} // namespace cstring_view
} // namespace beman

namespace beman::cstring_view::literals {
inline namespace cstring_view_literals {
// [cstring.view.literals], suffix for basic_cstring_view literals
constexpr cstring_view operator""_csv(const char* str, size_t len) noexcept { return basic_cstring_view(str, len); }
constexpr beman::cstring_view::cstring_view operator""_csv(const char* str, size_t len) noexcept {
return beman::cstring_view::basic_cstring_view(str, len);
}
#if __cpp_char8_t >= 201811L
constexpr u8cstring_view operator""_csv(const char8_t* str, size_t len) noexcept {
return basic_cstring_view(str, len);
constexpr beman::cstring_view::u8cstring_view operator""_csv(const char8_t* str, size_t len) noexcept {
return beman::cstring_view::basic_cstring_view(str, len);
}
#endif
constexpr u16cstring_view operator""_csv(const char16_t* str, size_t len) noexcept {
return basic_cstring_view(str, len);
constexpr beman::cstring_view::u16cstring_view operator""_csv(const char16_t* str, size_t len) noexcept {
return beman::cstring_view::basic_cstring_view(str, len);
}
constexpr u32cstring_view operator""_csv(const char32_t* str, size_t len) noexcept {
return basic_cstring_view(str, len);
constexpr beman::cstring_view::u32cstring_view operator""_csv(const char32_t* str, size_t len) noexcept {
return beman::cstring_view::basic_cstring_view(str, len);
}
constexpr wcstring_view operator""_csv(const wchar_t* str, size_t len) noexcept {
return basic_cstring_view(str, len);
constexpr beman::cstring_view::wcstring_view operator""_csv(const wchar_t* str, size_t len) noexcept {
return beman::cstring_view::basic_cstring_view(str, len);
}
} // namespace cstring_view_literals
} // namespace literals

template <class charT, class traits>
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os,
basic_cstring_view<charT, traits> str) {
return os << std::basic_string_view<charT, traits>(str);
}

} // namespace beman
} // namespace beman::cstring_view::literals

#if __cpp_lib_format >= 201907L
// [format.formatter.spec]
template <class charT, class traits>
struct std::formatter<beman::basic_cstring_view<charT, traits>, charT> {
struct std::formatter<beman::cstring_view::basic_cstring_view<charT, traits>, charT> {
formatter() = default;
constexpr auto parse(basic_format_parse_context<charT>& context) { return sv_formatter.parse(context); }
template <typename _Out>
auto format(beman::basic_cstring_view<charT, traits> csv, basic_format_context<_Out, charT>& context) const {
auto format(beman::cstring_view::basic_cstring_view<charT, traits> csv,
basic_format_context<_Out, charT>& context) const {
return sv_formatter.format(csv, context);
}

Expand All @@ -398,26 +406,36 @@ struct std::formatter<beman::basic_cstring_view<charT, traits>, charT> {

// [cstring.view.hash], hash support
template <>
struct std::hash<beman::cstring_view> {
auto operator()(const beman::cstring_view& sv) const noexcept { return std::hash<string_view>{}(sv); }
struct std::hash<beman::cstring_view::cstring_view> {
auto operator()(const beman::cstring_view::cstring_view& sv) const noexcept {
return std::hash<string_view>{}(sv);
}
};
#if __cpp_char8_t >= 201811L
template <>
struct std::hash<beman::u8cstring_view> {
auto operator()(const beman::u8cstring_view& sv) const noexcept { return std::hash<u8string_view>{}(sv); }
struct std::hash<beman::cstring_view::u8cstring_view> {
auto operator()(const beman::cstring_view::u8cstring_view& sv) const noexcept {
return std::hash<u8string_view>{}(sv);
}
};
#endif
template <>
struct std::hash<beman::u16cstring_view> {
auto operator()(const beman::u16cstring_view& sv) const noexcept { return std::hash<u16string_view>{}(sv); }
struct std::hash<beman::cstring_view::u16cstring_view> {
auto operator()(const beman::cstring_view::u16cstring_view& sv) const noexcept {
return std::hash<u16string_view>{}(sv);
}
};
template <>
struct std::hash<beman::u32cstring_view> {
auto operator()(const beman::u32cstring_view& sv) const noexcept { return std::hash<u32string_view>{}(sv); }
struct std::hash<beman::cstring_view::u32cstring_view> {
auto operator()(const beman::cstring_view::u32cstring_view& sv) const noexcept {
return std::hash<u32string_view>{}(sv);
}
};
template <>
struct std::hash<beman::wcstring_view> {
auto operator()(const beman::wcstring_view& sv) const noexcept { return std::hash<wstring_view>{}(sv); }
struct std::hash<beman::cstring_view::wcstring_view> {
auto operator()(const beman::cstring_view::wcstring_view& sv) const noexcept {
return std::hash<wstring_view>{}(sv);
}
};

#endif // BEMAN_CSTRING_VIEW_CSTRING_VIEW_HPP
10 changes: 5 additions & 5 deletions tests/beman/cstring_view/cstring_view.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <string>
#include <string_view>

using namespace beman::literals;
using namespace beman::cstring_view::literals;
using namespace std::literals;

TEST(StringView, ConstructionDestruction) {
std::string s = "hello";
beman::cstring_view h1 = "hello";
beman::cstring_view h2 = h1;
std::string s = "hello";
beman::cstring_view::cstring_view h1 = "hello";
beman::cstring_view::cstring_view h2 = h1;

EXPECT_EQ(h1.c_str(), h2.c_str());
EXPECT_NE(h1.c_str(), s.c_str());
Expand All @@ -31,7 +31,7 @@ TEST(StringView, ConstructionDestruction) {
auto first = h1.substr(0, 2);
auto end = h1.substr(2);
EXPECT_TRUE((std::is_same_v<decltype(first), std::string_view>));
EXPECT_TRUE((std::is_same_v<decltype(end), beman::cstring_view>));
EXPECT_TRUE((std::is_same_v<decltype(end), beman::cstring_view::cstring_view>));
EXPECT_EQ(first, "he");
EXPECT_EQ(end, "llo");
}
Loading