Environment variable assignment in Docker Compose – colon way

The documentation itself says both methods are working: You can use either an array or a dictionary. Now let’s forgive Docker for failing to use the proper terminology (an array is actually a sequence in YAML, a dictionary is a mapping) and have a look from the YAML perspective: A mapping is part of the … Read more

positional argument follows keyword argument

The grammar of the language specifies that positional arguments appear before keyword or starred arguments in calls: argument_list ::= positional_arguments [“,” starred_and_keywords] [“,” keywords_arguments] | starred_and_keywords [“,” keywords_arguments] | keywords_arguments Specifically, a keyword argument looks like this: tag=’insider trading!’ while a positional argument looks like this: …, exchange, …. The problem lies in that you … Read more

What do braces on the left-hand side of a variable declaration mean, such as in T {x} = y?

It’s not a declaration. It’s an assignment to a temporary. In std::unique_ptr<int> {p} = std::make_unique<int>(1);, std::unique_ptr<int> {p} creates a unique_ptr temporary that takes ownership of the object p points to, then std::make_unique<int>(1) is assigned to that temporary, which causes the object p points to to be deleted and the temporary to take ownership of the … Read more

Why does the equal to operator not work if it is not surrounded by spaces?

test (or [ expr ]) is a builtin function. Like all functions in bash, you pass its arguments as whitespace separated words. As the man page for bash builtins states: “Each operator and operand must be a separate argument.” It’s just the way bash and most other Unix shells work. Variable assignment is different. In … Read more

How to format multiple ‘or’ conditions in an if statement

I use this kind of pattern often. It’s very compact: Define a constant in your class: private static final Set<Integer> VALUES = Set.of(12, 16, 19); // Pre Java 9 use: VALUES = new HashSet<Integer>(Arrays.asList(12, 16, 19)); In your method: if (VALUES.contains(x)) { … } Set.of() returns a HashSet, which performs very well even for very … Read more

What is the correct syntax for defining a specialization of a function template?

Here are comments with each syntax: void foo(int param); //not a specialization, it is an overload void foo<int>(int param); //ill-formed //this form always works template <> void foo<int>(int param); //explicit specialization //same as above, but works only if template argument deduction is possible! template <> void foo(int param); //explicit specialization //same as above, but works … Read more