Skip to content

Instantly share code, notes, and snippets.

@kumar8600
Last active August 29, 2015 14:25
Show Gist options
  • Save kumar8600/3c1d2041dd4a6bc4ec86 to your computer and use it in GitHub Desktop.
Save kumar8600/3c1d2041dd4a6bc4ec86 to your computer and use it in GitHub Desktop.
Very simple naive any implementation type_info is not used. example: http://melpon.org/wandbox/permlink/cMPCv62OOcJFUOZZ
#pragma once
#include <memory>
#include <utility>
#include <functional>
#include <type_traits>
struct naive_any
{
template <typename T>
naive_any(T&& val) :
holder_(new typename std::decay<T>::type(std::forward<typename std::decay<T>::type>(val)),
[](void* ptr) { delete static_cast<typename std::decay<T>::type*>(ptr); })
{
}
void* get()
{
return holder_.get();
}
private:
std::unique_ptr<void, std::function<void(void*)>> holder_;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment