I Made my Own Data Type (C++)!
h
DynamicSquid

It's called "dsq::squid". The namespace "dsq" stands for "dynamic squid". If you want to see how I created this, take a look at the attached repl. Also, if you want to learn how to make your own data type, check out this tutorial. Otherwise, let's see what "squid" can do!


So my data type can actually accommodate most primitive types, making it dynamic. It can hold an integer, string, float, and a few more! Here's the basic syntax:

Here's the list of types it can hold:

  • bool
  • char
  • short, int, long
  • float, double
  • std::string

And the cool thing is, each type has it's own special method! Now let's take a look at bool.


Boolean Squids

As you can see, with the power of overloaded operators, we can make the object boolVar function like a traditional boolean!

Well, that's just bool. Next, characters!


Character Squid

What's special about char is that you can actually get the ascii value of it! Should come in handy sometimes.

Well, next up, integers!


Integer Squids

What makes the int type so special is the round method!

The place is based 10. So you can round it by the 10th place, 100th place, or even 100000th place. The default is 10.

The method is how you would like to round it. Up, down, or normally.

Up - 3.14 becomes 3.2;
Down - 3.14 becomes 3.1
Normal - 3.14 becomes 3.1

There's also a to_str() method which converts the int to a string.

Next up, decimals!


Decimal Squids

So for decimals, it's actually very similar to ints, but the round function works a little differently. You specify how many decimals places you would like to remove (default is 3).

Another special feature is the decimal_places() method, which counts the number of decimal places. It returns and int.

And lastly, strings!


String Squids

So a few things here. Subscript operator, multiplication, length, and erase.


And yeah! That's all the data types of the dsq::squid data type. Comment below if you want me to add more. Also, one more thing:

Don't forget to upvote!

You are viewing a single comment. View All
xxpertHacker

@DynamicSquid cout is type-safe already, but like printf, you can easily do printf("%d", "die system, die"). But can you explain how the squid& works?