-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement make_proxy_inplace and inplace_proxiable_target with freest…
…anding (#92) * Implement make_proxy_inplace and inplace_proxiable_target with freestanding * Add freestanding tests * Merge * Fix regression in code generation for `copying_default_dispatcher` * Fix build * Add noexcept * Remove empty line * Resolve comments
- Loading branch information
Showing
6 changed files
with
154 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#if __STDC_HOSTED__ | ||
#error "This file shall be compiled targeting a freestanding environment." | ||
#endif // __STDC_HOSTED__ | ||
|
||
#include "proxy.h" | ||
|
||
unsigned GetHash(int v) { return static_cast<unsigned>(v + 3) * 31; } | ||
unsigned GetHash(double v) { return static_cast<unsigned>(v * v + 5) * 87; } | ||
unsigned GetHash(const char* v) { | ||
unsigned result = 91u; | ||
for (int i = 0; v[i]; ++i) { | ||
result = result * 47u + v[i]; | ||
} | ||
return result; | ||
} | ||
unsigned GetDefaultHash() { return -1; } | ||
|
||
namespace spec { | ||
|
||
PRO_DEF_FREE_DISPATCH_WITH_DEFAULT(GetHash, ::GetHash, ::GetDefaultHash, unsigned()); | ||
PRO_DEF_FACADE(Hashable, GetHash); | ||
|
||
} // namespace spec | ||
|
||
extern "C" int main() { | ||
int i = 123; | ||
double d = 3.14159; | ||
const char* s = "lalala"; | ||
std::tuple<int, double> t{11, 22}; | ||
pro::proxy<spec::Hashable> p; | ||
p = &i; | ||
if (p() != GetHash(i)) { | ||
return 1; | ||
} | ||
p = &d; | ||
if (p() != GetHash(d)) { | ||
return 1; | ||
} | ||
p = pro::make_proxy_inplace<spec::Hashable>(s); | ||
if (p() != GetHash(s)) { | ||
return 1; | ||
} | ||
p = &t; | ||
if (p() != GetDefaultHash()) { | ||
return 1; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.