| 123456789101112131415161718192021222324252627 |
- //
- // any.h
- // program_args
- //
- // Created by Sam Jaffe on 2/25/23.
- //
- #pragma once
- #include <typeindex>
- namespace program::detail {
- class Any {
- public:
- Any() = default;
- template <typename T> Any(T const * ptr) : type_(typeid(T)), ptr_(ptr) {}
- template <typename T> T const * get() const {
- if (type_ != typeid(T)) { return nullptr; }
- return static_cast<T const *>(ptr_);
- }
- private:
- std::type_index type_ = typeid(void);
- void const * ptr_ = nullptr;
- };
- }
|