----------------------
Any code in GiNaC should comply to the C++ standard, as defined by ISO/IEC
-14882:1998(E). Don't use compiler-specific language extensions unless they
+14882:2011(E). Don't use compiler-specific language extensions unless they
are surrounded by appropriate "#ifdef"s, and you also provide a compliant
version of the code in question for other compilers.
Here is an example that features both indentation and alignment:
-class person
-{
+class person {
string name; // person's full name
int age; // age in years
};
of 8:
|-------|-------|-------|-------|-------|-------|------- <- tab stops
-class person
-{
+class person {
::::::::string name;::::// person's full name
::::::::int age;::::::::// age in years
};
Now somebody who prefers a tab-size of 4 looks at the code:
|---|---|---|---|---|---|---|---|---|---|---|---|---|--- <- tab stops
-class person
-{
+class person {
::::string name;::::// person's full name
::::int age;::::// age in years
};
(remember, ':' are Tabs, '.' are Spaces):
|-------|-------|-------|-------|-------|-------|------- <- tab stops
-class person
-{
+class person {
::::::::string name;..// person's full name
::::::::int age;......// age in years
};
tab-size, and it still looks good:
|---|---|---|---|---|---|---|---|---|---|---|---|---|--- <- tab stops
-class person
-{
+class person {
::::string name;..// person's full name
::::int age;......// age in years
};
x = -(y + z) / 2;
There are no spaces around the '<' and '>' used to designate template
-parameters. Unfortunately, a design flaw in C++ requires putting a space
-between two consecutive closing '>'s. We suggest that in this case you also
-put a space after the opening '<':
+parameters:
vector<int> vi;
- vector< list<int> > vli;
+ vector<list<int>> vli;
'*' and '&' in the declaration of pointer-to and reference-to variables
have a space before, but not after them:
One word: K&R, also known as "One True Brace Style", suitably extended for
C++. The opening brace goes at the end of the line, except for function
-bodies and classes. Really short functions can be written in one single line.
+bodies. Really short functions can be written in one single line.
if (a == b) {
// do something
// catchall
}
- class foo
- {
+ class foo {
public:
foo(int i) : x(i)
{