Skip to content

Just-for-fun implementation of polymorphic variables in C/C++

License

Notifications You must be signed in to change notification settings

styczynski/poly-var-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polymorphic variables in C++

Made by Styczynsky Digital Systems

Platform - Node

Just-for-fun implementation of polymorphic variables in C/C++

#include <var>
#include <var_math>
#include <var_test>
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:

#include <var>
using namespace variable;

int main() {
  var x = 0;
  x += "2.5";
  cout<<x<<"\n";

  return 0;
}

Or if you want to use printf/scanf style:

#include <var>
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):

  var x;
  cin >> x.castToFloat();

Or:

  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.