forked from andreasfertig/programming-with-cpp20
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (32 loc) · 719 Bytes
/
Copy pathmain.cpp
File metadata and controls
41 lines (32 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) Andreas Fertig.
// SPDX-License-Identifier: MIT
#include <iostream>
#ifdef WILL_NOT_COMPILE
struct Container {}; // #A Container without begin
int* begin(Container); // #B Free-function begin for Container
struct OtherContainer { // #C Container with begin
int* begin();
};
void Use(auto& c)
{
begin(c); // #D Call ::begin(Container)
std::begin(c); // #E Call STL std::begin
}
int* begin(Container) // #B Free-function begin for Container
{
std::cout << "begin(Container)\n";
return nullptr;
}
int* OtherContainer::begin()
{
std::cout << "OtherContainer::begin()\n";
return nullptr;
}
#endif
int main()
{
#ifdef WILL_NOT_COMPILE
Container c{};
Use(c);
#endif
}