Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@
.cache
.pytest_cache

.devcontainer
.devcontainer

lib/
16 changes: 9 additions & 7 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
function(DEFINE_EXAMPLE TARGET)
add_executable(example_${TARGET} "${TARGET}.cpp")
target_link_libraries(example_${TARGET} PRIVATE rsl_util)
target_link_libraries(example_${TARGET} PRIVATE rsl-util)
endfunction()

DEFINE_EXAMPLE(assert)
# DEFINE_EXAMPLE(assert)

add_executable(example_review
review.cpp
review_tu2.cpp
)
target_link_libraries(example_review PRIVATE rsl_util)
DEFINE_EXAMPLE(format)

# add_executable(example_review
# review.cpp
# review_tu2.cpp
# )
# target_link_libraries(example_review PRIVATE rsl_util)
Comment on lines +10 to +14
Copy link
Member

Choose a reason for hiding this comment

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

maybe just remove it, no need for keeping commented out code

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, I should probably re-enable that. I think something there broke, gonna take a look in a different PR

11 changes: 11 additions & 0 deletions example/format.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <rsl/print>
struct Foo {int a; char b;};
int main() {
rsl::println("a {[red]1} asdf {[blue]0} b", 42, 'c');
rsl::println("a {[cyan]} asdf {[green]} b", 42, 'c');
rsl::println("a {[yellow]!}{} sfdg {}{[reset]!} b", 42, 'c');

rsl::println("b={b}, a={a}", Foo(42, 'c'));
rsl::println("b={0.b}, a={0.a}", Foo(42, 'c'));
rsl::println("b={0.1}, a={0.0}", Foo(42, 'c'));
}
44 changes: 44 additions & 0 deletions include/rsl/_format_impl/accessor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once
#include <utility>
#include <tuple>
#include <meta>

namespace rsl::_format_impl {
template <std::meta::info Member>
struct MemberAccessor {
template <typename T>
friend constexpr decltype(auto) operator>>(T&& obj, MemberAccessor) {
return std::forward_like<T>(std::forward<T>(obj).[:Member:]);
}
};

template <std::size_t Idx>
struct SubscriptAccessor {
template <typename T>
friend constexpr decltype(auto) operator>>(T&& obj, SubscriptAccessor) {
return std::forward_like<T>(std::forward<T>(obj)[Idx]);
}
};

template <std::size_t Idx>
struct TupleAccessor {
template <typename T>
friend constexpr decltype(auto) operator>>(T&& obj, TupleAccessor) {
using std::get;
return get<Idx>(std::forward<T>(obj));
}
};

template <std::size_t Idx, typename... Fields>
struct Accessor {
static constexpr std::size_t index = Idx;

template <typename T>
static constexpr decltype(auto) get(T&& obj) {
return (std::forward<T>(obj) >> ... >> Fields{});
}
};

template <typename...>
struct AccessorList {};
}
Loading