Last active
August 29, 2015 14:25
-
-
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
This file contains hidden or 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
#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