-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3efbac0
Showing
33 changed files
with
17,187 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//------------------------------- Handle.h ------------------------------------- | ||
// | ||
// This software is in the public domain. The only restriction on its use is | ||
// that no one can remove it from the public domain by claiming ownership of it, | ||
// including the original authors. | ||
// | ||
// There is no warranty of correctness on the software contained herein. Use | ||
// at your own risk. | ||
// | ||
//------------------------------------------------------------------------------ | ||
|
||
#include "hash_append.h" | ||
#include "Handle.h" | ||
#include <unordered_set> | ||
|
||
// namespace acme is used to demonstrate example code. It is not proposed. | ||
|
||
namespace acme | ||
{ | ||
|
||
class Handle::CheshireCat | ||
{ | ||
std::unordered_set<int> data_; | ||
public: | ||
CheshireCat(int data1, int data2) | ||
{ | ||
data_.insert(data1); | ||
data_.insert(data2); | ||
} | ||
|
||
friend | ||
void | ||
hash_append(Handle::type_erased_hasher& h, CheshireCat const& c); | ||
}; | ||
|
||
void | ||
hash_append(Handle::type_erased_hasher& h, Handle::CheshireCat const& c) | ||
{ | ||
using xstd::hash_append; | ||
hash_append(h, c.data_); | ||
} | ||
|
||
Handle::Handle() | ||
: smile(new CheshireCat(1, 2)) | ||
{ | ||
} | ||
|
||
Handle::Handle(int data1, int data2) | ||
: smile(new CheshireCat(data1, data2)) | ||
{ | ||
} | ||
|
||
Handle::~Handle() | ||
{ | ||
delete smile; | ||
} | ||
|
||
} // acme |
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,61 @@ | ||
//------------------------------- Handle.h ------------------------------------- | ||
// | ||
// This software is in the public domain. The only restriction on its use is | ||
// that no one can remove it from the public domain by claiming ownership of it, | ||
// including the original authors. | ||
// | ||
// There is no warranty of correctness on the software contained herein. Use | ||
// at your own risk. | ||
// | ||
//------------------------------------------------------------------------------ | ||
|
||
#ifndef HANDLE_H | ||
#define HANDLE_H | ||
|
||
#include "hash_adaptors.h" | ||
|
||
// namespace acme is used to demonstrate example code. It is not proposed. | ||
|
||
namespace acme | ||
{ | ||
|
||
class Handle | ||
{ | ||
struct CheshireCat; // Not defined here | ||
CheshireCat* smile; // Handle | ||
|
||
public: | ||
Handle(); // Default Constructor | ||
~Handle(); // Destructor | ||
Handle(Handle const&) = delete; | ||
Handle& operator=(Handle const&) = delete; | ||
Handle(int data1, int data2); | ||
// Other operations... | ||
|
||
// Hash support | ||
using type_erased_hasher = acme::type_erased_hasher<std::size_t>; | ||
|
||
friend | ||
void | ||
hash_append(type_erased_hasher&, CheshireCat const&); | ||
|
||
template <class Hasher> | ||
friend | ||
void | ||
hash_append(Hasher& h, Handle const& x) | ||
{ | ||
using xstd::hash_append; | ||
if (x.smile == nullptr) | ||
hash_append(h, nullptr); | ||
else | ||
{ | ||
type_erased_hasher temp(std::move(h)); | ||
hash_append(temp, *x.smile); | ||
h = std::move(*temp.target<Hasher>()); | ||
} | ||
} | ||
}; | ||
|
||
} // acme | ||
|
||
#endif // HANDLE_H |
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,18 @@ | ||
This is a collection of software used to provide an example | ||
implementation of the proposal currently at: | ||
|
||
http://htmlpreview.github.io/?https://github.com/HowardHinnant/papers/blob/master/hashing.html | ||
|
||
And to demonstrate example software surrounding / using this proposal. | ||
|
||
Though there are a lot of files here, only one file contains an implementation | ||
of proposed software: | ||
|
||
hash_append.h | ||
|
||
Everything in namespace xstd, except for those things in xstd::detail, is | ||
proposed. Nothing else is. The only file containing anything in namespace | ||
xstd is hash_append.h. | ||
|
||
Currently hash_append.h is missing hash_append overloads for many std::containers | ||
and other objects. They should be added. |
Oops, something went wrong.