https://github.com/styczynski/poly-var-cpp
Just-for-fun implementation of polymorphic variables in C/C++
https://github.com/styczynski/poly-var-cpp
c-plus-plus cpp library polymorphic polymorphic-types variables-and-their-usages
Last synced: 10 days ago
JSON representation
Just-for-fun implementation of polymorphic variables in C/C++
- Host: GitHub
- URL: https://github.com/styczynski/poly-var-cpp
- Owner: styczynski
- License: mit
- Created: 2017-03-01T05:53:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-13T16:40:10.000Z (over 8 years ago)
- Last Synced: 2025-03-05T16:16:22.718Z (over 1 year ago)
- Topics: c-plus-plus, cpp, library, polymorphic, polymorphic-types, variables-and-their-usages
- Language: C++
- Size: 48.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Polymorphic variables in C++
[![Made by Styczynsky Digital Systems][badge sts]][link styczynski]
[![Platform - Node][badge support ccpp]][link styczynski]
Just-for-fun implementation of polymorphic variables in C/C++
```c++
#include
#include
#include
using namespace variable;
int main(void) {
/* Constructing a polymorphic-type tree */
var hmap = var::Hashmap;
hmap["foo"] = "bar";
var a = hmap.ref();
var ref = {a.ref(), 42};
var ref2 = {ref.ref(), 69, 25};
var tree = { {{}, 12, {}}, "ala", {{}, 69, {}} };
vardbg(tree);
return 0;
}
```
## Usage
Clone the repository, go to the directory where it's placed
and do `make` to get information about functionality of makefile.
If you want to compile all examples do `make all`
And then run any of the examples by running `make run-example-aritm`, `make run-example-tree` etc.
The basic usage looks like this:
```c++
#include
using namespace variable;
int main() {
var x = 0;
x += "2.5";
cout<
using namespace variable;
int main() {
var x = 0;
x += "2.5";
printf("%d", (int)x);
return 0;
}
```
You can read the standard input too (floats for example):
```c++
var x;
cin >> x.castToFloat();
```
Or:
```c++
var x;
scanf("%f", (float*)x);
```
## More examples
Checkout examples/src for details about functionality of the module.
Also you can see ./include/var.h to get more details.
[badge sts]: https://img.shields.io/badge/-styczynsky_digital_systems-blue.svg?style=flat-square&logoWidth=20&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABYAAAAXCAYAAAAP6L%2BeAAAABmJLR0QA%2FwD%2FAP%2BgvaeTAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH4AgSEh0nVTTLngAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAm0lEQVQ4y2Pc%2Bkz2PwMNAAs2wVMzk4jSbJY%2BD6ccEwONACMsKIh1JSEgbXKeQdr4PO1cPPQMZiGkoC7bkCQD7%2Fx7znDn35AOClK9PEJSBbNYAJz999UGrOLocsM0KHB5EZ%2FXPxiVMDAwMDD8SP3DwJA6kFka5hJCQOBcDwMDAwPDm3%2FbGBj%2BbR8tNrFUTbiAB8tknHI7%2FuTilAMA9aAwA8miDpgAAAAASUVORK5CYII%3D
[badge support ccpp]: https://img.shields.io/badge/platform-c%2Fc%2B%2B-blue.svg?style=flat-square&logoWidth=20&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAAXNSR0IArs4c6QAAAARnQU1BAACx%0Ajwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAANTSURBVEhLjVRLSJVREJ6bXokeSJGF4CbcGZXQ%0AIoKCWlekbVr4uEIGSpsgzWhTtslsY0LYw0ytbNG7zG5ClC0MScNSaCElhhl2r%2BKDEBK6zTfnzP%2Bf%0A%2B1D68P9nzry%2BmTn%2FNRBj0H8i1PSJKIDwALVVbDdGhlsiEAiIVBvOS5LArAmhq1xcYAjMmyhzVTo1%0Alm6BY1kICQoq3E4%2BfJulK91jpqLY4Ffd5rChuXwrBdOMA%2FmJ9bxJIJQAMN1rsG%2BPh%2BuP8Qrzk%2BoA%0ASZP4q%2FGBHE61pbSk1VCUNQRpHfe%2BvEngPPtwhMaiC14npgRKSRA18O7XrQ6aTMbA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