Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14854f6

Browse files
author
dev0
committed
[hcheng] advanced programming: namespace and declaration and enable argument-dependent lookup
1 parent ace124d commit 14854f6

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <iostream>
2+
#include "macro.hpp"
3+
MXT_NAMESPACE_BEGIN(framework1)
4+
template<typename T>
5+
inline bool is_empty(T const& x) {
6+
std::cout << "framework1::is_empty master template " << std::endl;
7+
return x.empty();
8+
}
9+
10+
template<>
11+
inline bool is_empty(const char* const& x) {
12+
std::cout << "framework1::is_empty specification" << std::endl;
13+
return x == 0 || *x == 0;
14+
}
15+
16+
MXT_NAMESPACE_END(framework1)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "framework1.hpp"
2+
3+
MXT_NAMESPACE_BEGIN(framework2)
4+
5+
using framework1::is_empty;
6+
template<typename string_t>
7+
void do_something(string_t const &x) {
8+
//if (framework1::is_empty(x)) // it causes error in framework3.cpp when call framework2::do_something(s)
9+
if (!is_empty(x))
10+
{
11+
}
12+
}
13+
MXT_NAMESPACE_END(framework2)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "framework2.hpp"
2+
namespace framework3 {
3+
class EmptyString
4+
{
5+
};
6+
7+
bool is_empty(const EmptyString&x) {
8+
std::cout << "framework3::is_empty" << std::endl;
9+
return true;
10+
}
11+
}
12+
13+
int main(int argc, char** argv) {
14+
framework3::EmptyString s;
15+
framework2::do_something(s);
16+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define MXT_NAMESPACE_BEGIN(self) namespace self {
2+
#define MXT_NAMESPACE_END(self) }

0 commit comments

Comments
 (0)