Skip to content

gwankyun/any

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

any

std::any的C++98實現,實現了大部分功能,無依賴。

CMake引入

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(CMakePrintHelpers)

set(project any)
project(${project})

set(Any_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
find_package(Any)
if(Any_FOUND)
    cmake_print_variables(Any_INCLUDE_DIRS)
endif()

add_executable(${project})
target_sources(${project}
  PRIVATE src/main.cpp)

target_link_libraries(${project}
  PUBLIC Any::Any)

C++使用

#include <any.hpp>

std::vector<int> vec;
vec.push_back(1);

any a = make_any<std::vector<int>>(vec);
std::vector<int>* pvec = any_cast<std::vector<int>>(&a);
if (pvec != NULL)
{
    assert(pvec->at(0) == vec[0]);
}

About

std::any in C++98

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published