Skip to content

Commit

Permalink
chore: Clean comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cwahn committed Mar 7, 2024
1 parent f4f7680 commit fe7364a
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 166 deletions.
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ project(
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED On)

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-backtrace-limit=0")


if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
message(WARNING "Copy-elision (RVO, NRVO) is not guraanteed.\n")

Expand Down Expand Up @@ -61,11 +58,10 @@ endfunction()

# ! temp
# Set verbose makefile output
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Enable verbose output" FORCE)
# set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Enable verbose output" FORCE)

add_library(efp INTERFACE)
target_include_directories(efp INTERFACE "./include")
# target_compile_features(efp INTERFACE cxx_std_11)

# Check if this CMakeLists.txt is the top-most CMake project
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ int main() {
```cpp
const String name_0 = "Lighthouse";
const String name_1 = "Tinker Bell";

println("{}", format("{} loves {}.", name_0, name_1));
```
Expand All @@ -118,6 +119,7 @@ CHECK(b == 42);
### File IO
```c++
auto file = File::open("test", "w+").move();

file.write("Hello, world!\nThis is a test file.\nEnd of test.");
file.close();
```
Expand All @@ -139,6 +141,7 @@ All tests passed (1055 assertions in 107 test cases)
## Requirements

- Requires C++ 11 or later.
- Also supporte freestanding env. with some limitations.

## Acknowledgement
- Formatting
Expand Down
4 changes: 3 additions & 1 deletion include/efp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
#include "./efp/numeric.hpp"
#include "./efp/scientific.hpp"
#include "./efp/sort.hpp"
#include "./efp/c_utility.hpp"
#include "./efp/io.hpp"
#include "./efp/string.hpp"
#include "./efp/format.hpp"
#include "./efp/concurrency.hpp"

// ! Deprecated
#include "./efp/c_utility.hpp"

#endif
6 changes: 0 additions & 6 deletions include/efp/cyclic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class Vcb {
static constexpr size_t ct_size = n;
static constexpr size_t ct_capacity = n;

// static_assert(ct_size >= 0, "ct_size must greater or equal than 0.");
// static_assert(ct_capacity >= 0, "ct_capacity must greater or equal than 0.");

Vcb() {
for (size_t i = 0; i < ct_size * 2; ++i) {
new (_buffer + i) A {};
Expand Down Expand Up @@ -174,9 +171,6 @@ class Vcq {
static constexpr size_t ct_size = dyn;
static constexpr size_t ct_capacity = n;

// static_assert(ct_size >= -1, "ct_size must greater or equal than -1.");
// static_assert(ct_capacity >= -1, "ct_capacity must greater or equal than -1.");

Vcq() {
// Buffers are uninitialized
_size = 0;
Expand Down
112 changes: 3 additions & 109 deletions include/efp/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,8 @@ namespace detail {
template<typename F>
using IsWildCard = IsSame<Arguments<F>, Tuple<>>;

// todo zero copy
// Wrapper for wild card to be callable with any arguments
// template<typename F>
// struct WildCardWrapper: public F {
// // Explicitly define a constructor to accept a lambda or any callable
// template<typename G>
// WildCardWrapper(G&& g) : F {std::forward<G>(g)} {}

// // Overload operator() to forward arguments to the callable's operator()
// template<typename... Args>
// inline auto operator()(Args&&...) const -> decltype(std::declval<F>()()) {
// return F::operator()();
// }
// };

// WildCardWrapper
// Zero-copy wrapper for wild card
template<typename F>
class WildCardWrapper {
public:
Expand Down Expand Up @@ -209,6 +196,7 @@ namespace detail {

// Overloaded
// Overloaded class for pattern matching
// todo Make it zero-copy
template<typename... Fs>
struct Overloaded;

Expand All @@ -221,13 +209,6 @@ namespace detail {
#endif
};

// template<typename F>
// struct Overloaded<F>: F {
// using F::operator();

// Overloaded(const F& f) : F {f} {}
// };

template<class F, class... Fs>
struct Overloaded<F, Fs...>: F, Overloaded<Fs...> {
using F::operator();
Expand Down Expand Up @@ -543,93 +524,6 @@ namespace detail {
};
};

// ! Explicit sanity check for match is deprecated.
// ! However, it maybe optionally enabled in the futere.
// Match branch sanity check

// // Wild card will be considered as a irrelevant branch
// template<typename F>
// using IsRelevantBranch = Any<IsInvocable<F, A>, IsInvocable<F, As>...>;

// // WildCardIffLast
// template<typename... Fs>
// struct WildCardIffLast {};

// template<typename F>
// struct WildCardIffLast<F>: IsWildCard<F> {};

// template<typename F, typename... Fs>
// struct WildCardIffLast<F, Fs...>: WildCardIffLast<Fs...> {};

// // AllButLastAreRelevant
// template<typename... Fs>
// struct AllButLastAreRelevant {};

// template<typename F>
// struct AllButLastAreRelevant<F>: True {};

// template<typename F, typename... Fs>
// struct AllButLastAreRelevant<F, Fs...>:
// Conditional<IsRelevantBranch<F>::value, AllButLastAreRelevant<Fs...>, False> {};

// // todo Make it more stricter only excpeting explicitly invocable branches
// // RemoveFirstInvocable
// template<typename Alt, typename List>
// struct _RemoveFirstInvocable {};

// template<typename Alt>
// struct _RemoveFirstInvocable<Alt, TypeList<>> {
// using Type = TypeList<>;
// };

// template<typename Alt, typename F, typename... Fs>
// struct _RemoveFirstInvocable<Alt, TypeList<F, Fs...>> {
// using Type = Conditional<
// IsInvocable<F, Alt>::value,
// TypeList<Fs...>,
// Prepend<F, typename _RemoveFirstInvocable<Alt, TypeList<Fs...>>::Type>>;
// };

// template<typename Alt, typename List>
// using RemoveFirstInvocable = typename _RemoveFirstInvocable<Alt, List>::Type;

// // Mutual Exhaustiveness
// // Check if the alternatives and the branches are mutually exhaustive
// template<typename AltList, typename BranchList>
// struct MutExhaust {};

// template<typename Alt, typename F>
// struct MutExhaust<TypeList<Alt>, TypeList<F>>: IsInvocable<F, Alt> {};

// template<typename Alt, typename... Alts, typename F, typename... Fs>
// struct MutExhaust<TypeList<Alt, Alts...>, TypeList<F, Fs...>>:
// Conditional<
// sizeof...(Alts) == sizeof...(Fs),
// MutExhaust<TypeList<Alts...>, RemoveFirstInvocable<Alt, TypeList<F, Fs...>>>,
// False> {};

// // PatternCheck
// template<typename, typename... Fs>
// struct _PatternCheck {};

// // No need to check if all the alternatives are covered
// // Only need to check if all the branches are relevant
// template<typename... Fs>
// struct _PatternCheck<True, Fs...> {
// using Type = AllButLastAreRelevant<Fs...>;
// };

// // If there is no wild card at the last branch, check if the alternatives and the branches are mutually exhaustive
// template<typename... Fs>
// struct _PatternCheck<False, Fs...> {
// using Type = MutExhaust<TypeList<A, As...>, TypeList<Fs...>>;
// };

// template<typename... Fs>
// using PatternCheck =
// typename _PatternCheck<Conditional<WildCardIffLast<Fs...>::value, True, False>, Fs...>::
// Type;

// Private member variables
alignas(_maximum({alignof(A), alignof(As)...})
) uint8_t _storage[_maximum({sizeof(A), sizeof(As)...})];
Expand Down
15 changes: 5 additions & 10 deletions include/efp/prelude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,9 @@ using ConcatReturn = Conditional<
CtCapacity<Ass>::value * CtCapacity<Element<Ass>>::value>>>,
Vector<Element<Element<Ass>>>>>;

// concat

// concat :: [[A]] -> [A]
template<typename Ass>
auto concat(const Ass ass) -> ConcatReturn<Ass> {
auto concat(const Ass& ass) -> ConcatReturn<Ass> {
ConcatReturn<Ass> res {};

const auto ass_len = length(ass);
Expand Down Expand Up @@ -318,8 +317,7 @@ using IntercalateReturn = Conditional<
- CtCapacity<As>::value>,
Vector<Element<Element<Ass>>>>>;

// intercalate

// intercalate :: [A] -> [[A]] -> [A]
template<typename As, typename Ass>
auto intercalate(const As& delimeter, const Ass& ass) -> IntercalateReturn<As, Ass> {
IntercalateReturn<As, Ass> result {};
Expand Down Expand Up @@ -368,17 +366,15 @@ auto intercalate(const As& delimeter, const Ass& ass) -> IntercalateReturn<As, A
return result;
}

// for_index

// for_index :: (size_t -> A) -> size_t -> void
template<typename F = void (*)(size_t)>
void for_index(const F& f, const size_t n) {
for (size_t i = 0; i < n; ++i) {
f(i);
}
}

// for_each_with_index

// for_each_with_index :: (size_t -> A -> void) -> [A] ... -> void
template<typename... Ass, typename F = void (*)(size_t, const Element<Ass>&...)>
void for_each_with_index(const F& f, const Ass&... seqs) {
const auto min_len = _min_length(seqs...);
Expand All @@ -398,7 +394,6 @@ void for_each_with_index_mut(const F& f, Ass&... seqs) {
}

// cartesian_for_each

template<typename As, typename F = void (*)(const Element<As>&)>
void cartesian_for_each(const F& f, const As& as) {
for_each(f, as);
Expand Down
4 changes: 1 addition & 3 deletions include/efp/sequence.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef SEQUENCE_HPP_
#define SEQUENCE_HPP_

// ct_capacity is compile time bound of length. It does not mean safety of access.
// However, actual capacity does means the length of memory safe to access.

#include "efp/cpp_core.hpp"
#include "efp/meta.hpp"
#include "efp/trait.hpp"
Expand Down Expand Up @@ -1417,6 +1414,7 @@ constexpr auto data(VectorView<A>& as) -> const A* {
return as.data();
}

// ! Very problematic
// #if defined(__STDC_HOSTED__) && __STDC_HOSTED__ == 1

// template<typename A>
Expand Down
2 changes: 0 additions & 2 deletions include/efp/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ using U32StringView = BasicStringView<char32_t>;
using U8StringView = BasicStringView<char8_t>;
#endif

// Use intercalate to join strings

// #if defined(__STDC_HOSTED__) && __STDC_HOSTED__ == 1

// template<typename A>
Expand Down
6 changes: 0 additions & 6 deletions test/efp/enum_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,6 @@ TEST_CASE("enum_match") {
a.match([&](int x) { b += 1; }, [&](False _) {}, [&]() {});

CHECK(b == 0.);

// ! Compilation should fail
// a.match(
// [&]()
// { b += 1; },
// [&]() {});
}

// todo Check priority of cosntructor argument then no match
Expand Down
28 changes: 4 additions & 24 deletions test/efp/test_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ const std::vector<double> stl_vector_5 {1., 2., 3., 4., 5.};
// Thread local side effectful

class MockHW {
public:
public:
struct Resource {
int id;
int value;
};

private:
private:
static thread_local int _next_id;
static thread_local std::vector<Resource> _resources;
static thread_local int _double_free_cnt;

public:
public:
MockHW() {}

// Optional: Method to reset the manager for reuse or testing
Expand Down Expand Up @@ -108,26 +108,6 @@ class MockHW {
return intercalate(String {", "}, strings);
}

// static std::string resource_state_to_string() {
// std::vector<std::string> strings;
// std::transform(
// _resources.begin(),
// _resources.end(),
// std::back_inserter(strings),
// [](const Resource& resource) { return std::to_string(resource.id); }
// );

// std::string result;
// for (size_t i = 0; i < strings.size(); ++i) {
// result += strings[i];
// if (i != strings.size() - 1) {
// result += ", ";
// }
// }

// return result;
// }

static bool is_sound() {
return _double_free_cnt == 0 && _resources.empty();
}
Expand All @@ -141,7 +121,7 @@ thread_local int MockHW::_double_free_cnt = 0;
class MockRaii {
MockHW::Resource _resource;

public:
public:
MockRaii() : _resource(MockHW::acquire()) {}

~MockRaii() {
Expand Down

0 comments on commit fe7364a

Please sign in to comment.