Skip to content

Commit f31788f

Browse files
committed
Example for Niebloid.
1 parent 6656a52 commit f31788f

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

code_examples/theory/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ add_executable(adl_nonfunc adl_nonfunc.cpp)
2424

2525
add_executable(adl_shutdown adl_shutdown.cpp)
2626
# Compile only
27+
28+
add_executable(adl_niebloid adl_niebloid.cpp)
29+
# Compile only

code_examples/theory/adl_niebloid.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <utility>
2+
3+
#include "adl_niebloid_code.h"
4+
int main() {
5+
calling_site();
6+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace dflt {
2+
namespace impl {
3+
template <typename T>
4+
concept HasCustomImpl = requires(T a) { do_something(a); };
5+
6+
struct DoSomethingFn {
7+
template <typename T> void operator()(T&& arg) const
8+
requires HasCustomImpl<T> { do_something(std::forward<T>(arg)); }
9+
template <typename T> void operator()(T&&) const
10+
requires (!HasCustomImpl<T>) { /* default implementation */ }
11+
};
12+
}
13+
14+
inline namespace var {
15+
constexpr inline auto do_something = impl::DoSomethingFn{};
16+
}
17+
}
18+
19+
namespace custom {
20+
struct X { friend void do_something(const X&){}; };
21+
struct Y {};
22+
}
23+
24+
void calling_site() {
25+
custom::X x;
26+
custom::Y y;
27+
dflt::do_something(x); // calls custom::do_something(const X&)
28+
dflt::do_something(y); // calls default implementation
29+
}

code_examples/theory/adl_shutdown_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ constexpr inline auto some_func = [](const auto&) {};
99
void calling_site() {
1010
Custom::X x;
1111
some_func(x); // calls ::some_func
12-
// Because ::some_func prevents ADL, Custom::some_func cannot be called.
12+
// Because ADL is skipped, Custom::some_func cannot be called.
1313
}

0 commit comments

Comments
 (0)