Skip to content

Commit

Permalink
feat: drop C-style ellipsis support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhihaoy committed Dec 9, 2024
1 parent b82e890 commit 1e08aa9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 94 deletions.
44 changes: 4 additions & 40 deletions include/std23/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "__functional_base.h"

#include <cstdarg>
#include <memory>
#include <new>

Expand All @@ -15,23 +14,12 @@ template<class Sig> struct _opt_fn_sig;
template<class R, class... Args> struct _opt_fn_sig<R(Args...)>
{
using function_type = R(Args...);
static constexpr bool is_variadic = false;

template<class... T>
static constexpr bool is_invocable_using =
std::is_invocable_r_v<R, T..., Args...>;
};

template<class R, class... Args> struct _opt_fn_sig<R(Args......)>
{
using function_type = R(Args...);
static constexpr bool is_variadic = true;

template<class... T>
static constexpr bool is_invocable_using =
std::is_invocable_r_v<R, T..., Args..., va_list>;
};

template<class R, class... Args> struct _copyable_function
{
struct lvalue_callable
Expand Down Expand Up @@ -85,7 +73,7 @@ template<class R, class... Args> struct _copyable_function
{}

explicit stored_object(T p) noexcept requires std::is_pointer_v<T>
: p_(p)
: p_(p)
{}

protected:
Expand Down Expand Up @@ -201,10 +189,7 @@ template<class S, class R, class... Args> class function<S, R(Args...)>

template<class T> using lvalue = std::decay_t<T> &;

using copyable_function =
std::conditional_t<signature::is_variadic,
_copyable_function<R, _param_t<Args>..., va_list &>,
_copyable_function<R, _param_t<Args>...>>;
using copyable_function = _copyable_function<R, _param_t<Args>...>;

using lvalue_callable = copyable_function::lvalue_callable;
using empty_target_object = copyable_function::empty_target_object;
Expand Down Expand Up @@ -334,31 +319,10 @@ template<class S, class R, class... Args> class function<S, R(Args...)>

friend bool operator==(function const &f, nullptr_t) noexcept { return !f; }

R operator()(Args... args) const requires(!signature::is_variadic)
R operator()(Args... args) const
{
return (*target())(std::forward<Args>(args)...);
}

#if defined(__GNUC__) && (!defined(__clang__) || defined(__INTELLISENSE__))
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-value"
#endif

R operator()(Args... args...) const
requires(signature::is_variadic and sizeof...(Args) != 0)
{
struct raii
{
va_list data;
~raii() { va_end(data); }
} va;
va_start(va.data, (args, ...));
return (*target())(std::forward<Args>(args)..., va.data);
}

#if defined(__GNUC__) && (!defined(__clang__) || defined(__INTELLISENSE__))
#pragma GCC diagnostic pop
#endif
};

template<class S> struct _strip_noexcept;
Expand All @@ -380,7 +344,7 @@ function(F *) -> function<_strip_noexcept_t<F>>;

template<class T>
function(T) -> function<_strip_noexcept_t<
_drop_first_arg_to_invoke_t<decltype(&T::operator()), void>>>;
_drop_first_arg_to_invoke_t<decltype(&T::operator()), void>>>;

template<auto V>
function(nontype_t<V>)
Expand Down
3 changes: 0 additions & 3 deletions tests/function/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ target_sources(run-function PRIVATE
"test_ctad.cpp"
"test_reference_semantics.cpp"
"test_nullable.cpp"
"test_va_args.cpp"
"test_nontype.cpp"
)
set_source_files_properties("test_va_args.cpp" PROPERTIES
COMPILE_DEFINITIONS $<$<CXX_COMPILER_ID:MSVC>:_CRT_NO_VA_START_VALIDATION>)
target_link_libraries(run-function PRIVATE nontype_functional kris-ut)
set_target_properties(run-function PROPERTIES OUTPUT_NAME run)
add_test(function run)
51 changes: 0 additions & 51 deletions tests/function/test_va_args.cpp

This file was deleted.

0 comments on commit 1e08aa9

Please sign in to comment.