Skip to content

Commit

Permalink
feat: drop C-style ellipsis support (#10)
Browse files Browse the repository at this point in the history
The "six dots" are deprecated in C++26 after the adoption of P3176. No
more fun!
  • Loading branch information
zhihaoy authored Dec 9, 2024
1 parent b228363 commit d7e63c0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 95 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,8 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# CMake presets
/CMakeSettings.json
/CMakeUserPresets.json
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......)>

This comment has been minimized.

Copy link
@Eisenwave

Eisenwave Dec 18, 2024

This six dots aren't a thing anymore, but the construct still exists as R(Args..., ...).

Isn't this commit removing a bit too much?

This comment has been minimized.

Copy link
@zhihaoy

zhihaoy Dec 18, 2024

Author Owner

Are you using this feature (ellipses in signature to wrap a function that takes va_list)? I added the feature for sarcasm, not for practical purposes.

This comment has been minimized.

Copy link
@Eisenwave

Eisenwave Dec 19, 2024

No, I'm the author of the proposal that deprecated the six-dot syntax. Stumbled upon this repo through GH code search when looking at how this is getting adopted.

So yeah, ..., .... is a bit of a meme feature; I'm not aware of anyone who actually relies on that.

{
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 d7e63c0

Please sign in to comment.