Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zonyitoo/variantcpp
Variant Type in C++
https://github.com/zonyitoo/variantcpp
Last synced: 3 months ago
JSON representation
Variant Type in C++
- Host: GitHub
- URL: https://github.com/zonyitoo/variantcpp
- Owner: zonyitoo
- Created: 2014-04-19T06:59:05.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-04-20T04:29:59.000Z (over 10 years ago)
- Last Synced: 2023-04-09T22:20:06.843Z (over 1 year ago)
- Language: C++
- Homepage:
- Size: 137 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
-----------
Variant CPP
-----------A flexible C++ data structure, which can contain any type
Just for fun. But I will continue to improve it. :P
*Note: This library is written in C++11 standard*
Usage
=====.. code:: cpp
#include "VariantList.hpp"
#include
#include
using namespace std;int main(int argc, char *argv[]) {
VariantList variant_list;variant_list.push_back(1); // int
variant_list.push_back(1.2); // double
variant_list.push_back("Hello"); // stringVariantList another_list;
another_list.push_back(10);
another_list.push_back(10.1f);variant_list.push_back(another_list); // !!
variant_list.push_back(variant_list); // !!
cout << variant_list << endl;
auto itr = variant_list.begin();
cout << "First: " << itr->get() << endl;
++ itr;
cout << "Second: " << itr->get() << endl;
++ itr;
cout << "Third: " << itr->get() << endl;*itr = make_variant(10.2); // Change element 3 "Hello" (std::string) to 10.2 (Double)
cout << "Third: " << itr->get() << endl;cout << variant_list << endl;
return 0;
}Run the previous code section will print
.. code::
[1, 1.2, Hello, [10, 10.1], [1, 1.2, Hello, [10, 10.1]]]
First: 1
Second: 1.2
Third: Hello
Third: 10.2
[1, 1.2, 10.2, [10, 10.1], [1, 1.2, Hello, [10, 10.1]]]TODO
====* Improve usability
* Implement other kind of variant data structure
License
=======MIT License