Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardHinnant committed Apr 27, 2014
0 parents commit 3efbac0
Show file tree
Hide file tree
Showing 33 changed files with 17,187 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Handle.cpp
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
61 changes: 61 additions & 0 deletions Handle.h
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
18 changes: 18 additions & 0 deletions README.txt
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.
Loading

0 comments on commit 3efbac0

Please sign in to comment.