Thanks to visit codestin.com
Credit goes to github.com

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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ It is a general-purpose library. The usage of no-STL, resource-tight embedded ap
EFP supports major higher-order functions including `for_each`, `map`, `filter`, `foldl`, `foldr`, `from_function`, `for_index`, `for_each_with_index`, `cartesian_for_each`, `map_with_index`, `cartesian_map` and many more.

### Zero-Copy Sequence Types
Copying sequence is often an expensive operation yet does not necessary. Move semantic, introduced in C++ 11 somewhat eases the problem. However, the move helps little about stack sequence types like `std::array`, since moving such types is essentially a series of element-wise moves which is often no better than an element-wise copy.
Copying sequence is often an expensive operation yet does not necessary. Move semantic, size_troduced in C++ 11 somewhat eases the problem. However, the move helps little about stack sequence types like `std::array`, since moving such types is essentially a series of element-wise moves which is often no better than an element-wise copy.

There is a better option, copy-elision (Return Value Optimization and Named Return Value Optimization). It makes returning heavy data free. Unfortunately, copy-elision is not guaranteed but at the compiler's discretion. (Since, C++ 17 some of them are guaranteed.)

Expand Down Expand Up @@ -55,7 +55,7 @@ WIP

using namespace efp;

constexpr size_t n = 10;
constexpr int n = 10;

int main()
{
Expand Down
22 changes: 11 additions & 11 deletions include/c_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@

namespace efp
{
// FunctionPointerTypeImpl
// FunctionPosize_terTypeImpl

template <typename, typename...>
struct FunctionPointerTypeImpl
struct FunctionPosize_terTypeImpl
{
};

template <typename F, typename... Args>
struct FunctionPointerTypeImpl<F, Tuple<Args...>>
struct FunctionPosize_terTypeImpl<F, Tuple<Args...>>
{
using type = Return<F> (*)(Args...);
};

// FunctionPointerType
// FunctionPosize_terType

template <typename F>
using FunctionPointerType = typename FunctionPointerTypeImpl<F, Arguments<F>>::type;
using FunctionPosize_terType = typename FunctionPosize_terTypeImpl<F, Arguments<F>>::type;

// LambdaPointer
// LambdaPosize_ter

template <typename F>
struct LambdaPointer
struct LambdaPosize_ter
{
template <typename Tpl>
struct Helper
Expand All @@ -46,16 +46,16 @@ namespace efp
};

template <typename F>
void *LambdaPointer<F>::inner_ptr = nullptr;
void *LambdaPosize_ter<F>::inner_ptr = nullptr;

// func_ptr

template <typename F>
// ! Take caution on the lifetime of the argument.
static FunctionPointerType<F> func_ptr(F &f)
static FunctionPosize_terType<F> func_ptr(F &f)
{
LambdaPointer<F>::inner_ptr = (void *)&f;
return (FunctionPointerType<F>)LambdaPointer<F>::template Helper<Arguments<F>>::call;
LambdaPosize_ter<F>::inner_ptr = (void *)&f;
return (FunctionPosize_terType<F>)LambdaPosize_ter<F>::template Helper<Arguments<F>>::call;
}
}

Expand Down
11 changes: 7 additions & 4 deletions include/cpp_core.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#ifndef CPP_CORE_HPP
#define CPP_CORE_HPP

#include <stdint.h> // Fixed-width integers (e.g., uint8_t, int16_t, etc.)
#include <stddef.h> // Common macros (e.g., NULL, size_t) and limit constants.
// C cores
#include <stdint.h> // Fixed-width size_tegers (e.g., uint8_t, size_t16_t, etc.)
#include <stddef.h> // Common macros (e.g., NULL, int) and limit constants.
#include <stdlib.h> // Standard utility functions (e.g., malloc, free, atoi, itoa).
#include <stdio.h> // Input and output utilities (e.g., sprintf, snprintf).
#include <string.h> // String handling functions (e.g., strcpy, strlen, strcat).
#include <float.h> // Macros for numeric limits
#include <math.h> // Common mathematical functions (e.g., sin, cos, abs).
#include <stdarg.h>

#include <cstddef> // Defines size_t, ptrdiff_t, and nullptr_t
#include <cstdint> // Defines fixed width integer types like int32_t, uint8_t, etc.
// C++
#include <cstddef> // Defines int, ptrdiff_t, and nullptr_t
// #include <cstdsize_t> // Defines fixed width size_teger types like size_t32_t, uint8_t, etc.
#include <new> // Defines operator new and operator delete, which can be overridden for custom memory management.

#endif
40 changes: 20 additions & 20 deletions include/cyclic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

namespace efp
{
template <typename A, int n>
template <typename A, size_t n>
class Vcb
: public SequenceBase<Vcb<A, n>>
{
public:
using Element = A;
using SizeType = int;
using SizeType = size_t;

static constexpr int ct_len = n;
static constexpr int ct_cap = n;
static constexpr size_t ct_len = n;
static constexpr size_t ct_cap = n;

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

Vcb()
: buffer_{}
Expand Down Expand Up @@ -95,28 +95,28 @@ namespace efp
A *data_;
};

template <typename A, int n>
template <typename A, size_t n>
class SequenceTrait<Vcb<A, n>>
{
public:
using Element = A;
static constexpr int ct_len = n;
static constexpr int ct_cap = n;
static constexpr size_t ct_len = n;
static constexpr size_t ct_cap = n;
};

template <typename A, int n>
template <typename A, size_t n>
class Vcq
: public SequenceBase<Vcq<A, n>>
{
public:
using Element = A;
using SizeType = int;
using SizeType = size_t;

static constexpr int ct_len = dyn;
static constexpr int ct_cap = n;
static constexpr size_t ct_len = dyn;
static constexpr size_t ct_cap = n;

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

Vcq()
: buffer_{}
Expand Down Expand Up @@ -210,19 +210,19 @@ namespace efp

private:
Array<A, ct_cap * 2> buffer_ = {};
int size_ = 0;
size_t size_ = 0;
A *read_;
A *write_;
A *middle_;
};

template <typename A, int n>
template <typename A, size_t n>
class SequenceTrait<Vcq<A, n>>
{
public:
using Element = A;
static constexpr int ct_len = dyn;
static constexpr int ct_cap = n;
static constexpr size_t ct_len = dyn;
static constexpr size_t ct_cap = n;
};

}
Expand Down Expand Up @@ -349,7 +349,7 @@ namespace efp
// A *in_data = in_buffer->data;
// size_t in_length = in_buffer->len;

// // for (int i = 0; i < in_length; i++)
// // for (size_t i = 0; i < in_length; i++)
// // {
// // out_buffer.push_back(in_data[i]);
// // }
Expand Down
10 changes: 1 addition & 9 deletions include/enum_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace efp
template <typename B>
struct Binded
{
static const bool value = std::is_same<A, B>::value;
static const bool value = IsSame<A, B>::value;
};
};

Expand Down Expand Up @@ -351,7 +351,6 @@ namespace efp
STAMP2(0, CASE)

default:
// assert(0);
abort();
}
}
Expand All @@ -371,7 +370,6 @@ namespace efp
STAMP4(0, CASE)

default:
// assert(0);
abort();
}
}
Expand All @@ -391,7 +389,6 @@ namespace efp
STAMP8(0, CASE)

default:
// assert(0);
abort();
}
}
Expand All @@ -411,7 +408,6 @@ namespace efp
STAMP16(0, CASE)

default:
// assert(0);
abort();
}
}
Expand All @@ -431,7 +427,6 @@ namespace efp
STAMP32(0, CASE)

default:
// assert(0);
abort();
}
}
Expand All @@ -451,7 +446,6 @@ namespace efp
STAMP64(0, CASE)

default:
// assert(0);
abort();
}
}
Expand All @@ -471,7 +465,6 @@ namespace efp
STAMP128(0, CASE)

default:
// assert(0);
abort();
}
}
Expand All @@ -491,7 +484,6 @@ namespace efp
STAMP256(0, CASE)

default:
// assert(0);
abort();
}
}
Expand Down
25 changes: 10 additions & 15 deletions include/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ namespace efp
template <typename TypeSeq, typename T, typename Ts>
using SubstituteTypeSeq = typename SubstituteTypeSeqImpl<TypeSeq, T, Ts>::Type;

// Define a typelist of integer types
// Define a typelist of size_teger types
using IntegeralTypes = MakeTypeSeq<
char, signed char, int, long, long long,
unsigned char, unsigned, unsigned long, unsigned long long>;

// IsIntegeralType checks if a type T is in the list of integer types
// IsIntegeralType checks if a type T is in the list of size_teger types
template <typename T>
struct IsIntegeralType
{
Expand Down Expand Up @@ -198,14 +198,14 @@ namespace efp
// StringToChars

// StringToCharsImpl converts a compile-time string to a type list of Char types
template <typename Str, size_t pos, char c>
template <typename Str, int pos, char c>
struct StringToCharsImpl
{
using Tail = typename StringToCharsImpl<Str, pos + 1, Str::string()[pos + 1]>::Type;
using Type = TypeSeq<Char<c>, Tail>;
};

template <typename Str, size_t pos>
template <typename Str, int pos>
struct StringToCharsImpl<Str, pos, '\0'>
{
using Type = Nil;
Expand Down Expand Up @@ -244,11 +244,6 @@ namespace efp
}
};

template <typename T>
struct AlwaysFalse : False
{
};

template <typename T>
struct TypeToFormat;

Expand Down Expand Up @@ -344,15 +339,15 @@ namespace efp

static constexpr bool is_s_fmt = ContainsTypeSeq<FL, Char<'s'>>::value;
static constexpr bool is_string =
IsSame<char, CVRemoved<PointerRemoved<RawType>>>::value;
IsSame<char, CVRemoved<Posize_terRemoved<RawType>>>::value;

static constexpr bool is_int = IsIntegeralType<RawType>::value;
static constexpr bool is_size_t = IsIntegeralType<RawType>::value;
static constexpr bool is_x_fmt = ContainsTypeSeq<FL, Char<'x'>>::value;

using RawFormat = typename TypeToFormat<T>::Type;

using UIntXFormat = Conditional<
is_int && is_x_fmt,
is_size_t && is_x_fmt,
SubstituteTypeSeq<
SubstituteTypeSeq<RawFormat, Char<'d'>, Char<'x'>>,
Char<'u'>, Char<'x'>>,
Expand All @@ -373,7 +368,7 @@ namespace efp
template <typename T, typename FL>
using FormatString = typename FormatStringImpl<T, FL>::Type;

template <class InList, class OutList, size_t Counter>
template <class InList, class OutList, int Counter>
struct FindBrace;

// Specialization for finding the closing brace
Expand All @@ -385,15 +380,15 @@ namespace efp
};

// General case: iterating through the list
template <char C, class InList, class OutList, size_t N>
template <char C, class InList, class OutList, int N>
struct FindBrace<TypeSeq<Char<C>, InList>, OutList, N>
: public FindBrace<InList, AppendTypeSeq<OutList, Char<C>>, N>
{
static_assert(C != '{', "Found nested braces: {...{...}...}! Maybe you want to mask the outer one?");
};

// Error case: missing closing brace
template <class OutList, size_t N>
template <class OutList, int N>
struct FindBrace<Nil, OutList, N>
{
static_assert(N + 1 == N, "Missing } after {.");
Expand Down
4 changes: 2 additions & 2 deletions include/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace efp
{
length = strlen(data);
}
size_t written = fwrite(data, sizeof(char), length, file_);
int written = fwrite(data, sizeof(char), length, file_);
return written == length;
}
else
Expand Down Expand Up @@ -146,7 +146,7 @@ namespace efp
if (strchr(mode_, 'b'))
{
// Write binary data
size_t written = fwrite(data.data(), sizeof(char), data.size(), file_);
int written = fwrite(data.data(), sizeof(char), data.size(), file_);
return written == data.size();
}
else
Expand Down
Loading