forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Implement std::not_fn<NTTP> (llvm#86133)
Implement `std::not_fn<NTTP>` from "P2714R1 Bind front and back to NTTP callables".
- Loading branch information
1 parent
c391082
commit c91d805
Showing
12 changed files
with
446 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
libcxx/test/libcxx/utilities/function.objects/func.not.fn/not_fn.nttp.compile.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 | ||
|
||
// <functional> | ||
|
||
// Type of `std::not_fn<NTTP>()` is always empty. | ||
|
||
#include <functional> | ||
#include <type_traits> | ||
|
||
struct NonEmptyFunctionObject { | ||
bool val = true; | ||
bool operator()() const; | ||
}; | ||
|
||
bool func(); | ||
|
||
struct SomeClass { | ||
bool member_object; | ||
bool member_function(); | ||
}; | ||
|
||
using ResultWithEmptyFuncObject = decltype(std::not_fn<std::false_type{}>()); | ||
static_assert(std::is_empty_v<ResultWithEmptyFuncObject>); | ||
|
||
using ResultWithNotEmptyFuncObject = decltype(std::not_fn<NonEmptyFunctionObject{}>()); | ||
static_assert(std::is_empty_v<ResultWithNotEmptyFuncObject>); | ||
|
||
using ResultWithFunctionPointer = decltype(std::not_fn<&func>()); | ||
static_assert(std::is_empty_v<ResultWithFunctionPointer>); | ||
|
||
using ResultWithMemberObjectPointer = decltype(std::not_fn<&SomeClass::member_object>()); | ||
static_assert(std::is_empty_v<ResultWithMemberObjectPointer>); | ||
|
||
using ResultWithMemberFunctionPointer = decltype(std::not_fn<&SomeClass::member_function>()); | ||
static_assert(std::is_empty_v<ResultWithMemberFunctionPointer>); |
24 changes: 24 additions & 0 deletions
24
libcxx/test/libcxx/utilities/function.objects/func.not.fn/not_fn.nttp.nodiscard.verify.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 | ||
|
||
// <functional> | ||
|
||
// Test the libc++ extension that std::not_fn<NTTP> is marked as [[nodiscard]]. | ||
|
||
#include <functional> | ||
#include <type_traits> | ||
|
||
void test() { | ||
using F = std::true_type; | ||
std::not_fn<F{}>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
|
||
auto negated = std::not_fn<F{}>(); | ||
negated(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.