Contents
Syntax
The syntax for
struct{options}(name) { //struct block }
@struct{options}(name) { //struct block }
Description
The
Note:
@struct(s) { # struct block }!
Options
The following options are available for
option | description |
---|---|
struct block uses |
|
struct block uses |
|
parse struct block at definition time | |
option | description |
f++ example
Examples of
- struct(circle)
- {
- if(params.size() != 2)
- error("circle: expected 2 parameters, got $[params.size]")
- :=(int, $[params.name].radius = params.at(0))
- :=(string, $[params.name].colour = params.at(1))
- }
- :=(circle, c(2, "fluro green"))
- console("radius: ", c.radius)
- console("colour: ", c.colour)
- struct(pair)
- {
- if(types.size() != 2)
- error("pair: expected 2 types, got types.size()")
- if(params.size() != 2)
- error("pair: expected 2 parameters, got params.size()")
- :=(types.at(0), $[params.name].first = params.at(0))
- :=(types.at(1), $[params.name].second = params.at(1))
- }
- :=(pair<int, string>, p(10, "hello, world!"))
- console("p.first: ", p.first)
- console("p.second: ", p.second)
- struct(vector)
- if(params.size() != 2)
- error("vector: expected 2 parameters, got ", params.size())
- int $[params.name].size = params.at(0)
- for{!s}(int i=0; i<$[params.name].size; i+=1; forget(i))
- "types.at(0)" $[params.name][$[i]](params.at(1))
- function{pb}($[params.name].str)
- join($[params.name], " ")
- function{pb}($[params.name].print)
- console($[params.name].str())
- function{pb, !s}($[params.name].push_back)
- "@types.at(0)" $[params.name][\$[$[params.name].size]](params.at(0))
- ++($[params.name].size)
- function{pb}($[params.name].pop_back)
- --($[params.name].size)
- forget($[params.name][\$[$[params.name].size]])
- vector<int> v(5, 4);
- v.push_back(32);
- console(v.str())
- console(v.size)
- v.pop_back();
- console(v.str())
- console(v.size)
n++ example
Examples of
- @struct(circle)
- {
- if(params.size() != 2)
- error("circle: expected 2 parameters, got $[params.size]")
- :=(int, $[params.name].radius = params.at(0))
- :=(string, $[params.name].colour = params.at(1))
- }
- @:=(circle, c(2, "fluro green"))
- @console("radius: ", c.radius)
- @console("colour: ", c.colour)
- @struct(pair)
- {
- if(types.size() != 2)
- error("pair: expected 2 types, got types.size()")
- if(params.size() != 2)
- error("pair: expected 2 parameters, got params.size()")
- :=(types.at(0), $[params.name].first = params.at(0))
- :=(types.at(1), $[params.name].second = params.at(1))
- }
- @:=(pair<int, string>, p(10, "hello, world!"))
- @console("p.first: ", p.first)
- @console("p.second: ", p.second)