What do the double curly braces in the following line of C++ code mean?
piranha::symbol_set ss({{piranha::symbol(detail::poly_print(var))}});
For context, this is from a file in the SymEngine code ("symengine/polys/uintpoly_piranha.h"
), which can be found at the link below, as can the Piranha library which is used in the above line.
I know single curly braces are used as initializer lists, but the meaning of the double curly braces within the set of parentheses makes little sense to me.
The main thing I found on double curly braces was this post, but it does not seem applicable here.
Also, I apologize for linking source code like this but I am unsure of how to make a smaller example given my lack of understanding.
Thanks!
In programming, curly braces (the { and } characters) are used in a variety of ways. In C/C++, they are used to signify the start and end of a series of statements. In the following expression, everything between the { and } are executed if the variable mouseDOWNinText is true.
Using curly braces to initialize a variable also prevents narrowing. Narrowing, or more precisely narrowing conversion, is the implicit conversion of arithmetic values that includes a loss of accuracy.
Different programming languages have various ways to delineate the start and end points of a programming structure, such as a loop, method or conditional statement. For example, Java and C++ are often referred to as curly brace languages because curly braces are used to define the start and end of a code block.
Data is represented in name/value pairs. Curly braces hold objects and each name is followed by ':'(colon), the name/value pairs are separated by , (comma). Square brackets hold arrays and values are separated by ,(comma).
Curly braces (also referred to as just “braces” or as “curly brackets”) are a major part of the C and C++ programming languages. They are used in several different constructs, outlined below, and this can sometimes be confusing for beginners. An opening curly brace, {must always be followed by a closing curly brace }.
If you see two consecutive curly braces { in java code, it is an usage of double brace initialization. First brace is creation of an anonymous inner class. Without considering the second brace if you see the first brace alone then its nothing new for us. We have created many anonymous inner classes in such a way.
Java Double Brace Initialization. Double brace initialization is a combination of two separate process in java. There are two { braces involved in it. If you see two consecutive curly braces { in java code, it is an usage of double brace initialization.
You can use brace initialization anywhere you would typically do initialization—for example, as a function parameter or a return value, or with the new keyword: In /std:c++17 mode, the rules for empty brace initialization are slightly more restrictive. See Derived constructors and extended aggregate initialization.
Curly braces can be used to describe
std::initializer_list
of symbols, see the corresponding constructor) symbol
using the move constructor, see the corresponding constructor)symbol{parameters}
you can just write {parameters}
. This also works for return values and variable initialization.So what actually happens in this line is:
std::string
is returned from detail::poly_print(var)
piranha::symbol
symbol
, constructing another symbol
piranha::symbol
is then stored in a std::initializer_list
piranha::symbol_set
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With