Author Topic: Code Completion for brace initialization style  (Read 4642 times)

Offline jlhouchin

  • Single posting newcomer
  • *
  • Posts: 3
Code Completion for brace initialization style
« on: May 15, 2014, 09:28:09 pm »
Hello,

I am new to Code::Blocks and learning C++.

I am working my way through C++ Primer Plus. I am attempting to learn good coding practices while learning modern C++.
When I type out the example code in the book I attempt to use what I read as best practice such as:
Code
 
std::cout << " instead of ";
using namespace std;

In the book it teaches about variable initialization including C++11 forms.

Code
// Yes I know the below in total will not compile
// as I am using the same variable names for simplicity
// I mention C++11 but do not state that it is limited to C++11 and beyond.

const float kVar{42};
// C++11 brace form initialization
// compiles fine, but no code completion

const float kVar = {42};
// C++11 brace form initialization with =
// compiles fines, has code completion

const float kVar(42);
// compiles fine, has code completion

const float kVar = 42;
// compiles fines, has code completion

I searched the forums and Code::Blocks settings.

I can find no way to enable code completion for the brace initialization style.

Since this is legal and proper code, it would be nice for code completion to work with it. In the book it somewhat implies that this might be the preferred way to initialize in the future.

Quote
In the future, texts may introduce you to initialization using the brace forms and mention the other forms as historical oddities retained for backward compatibility.

And yes, I understand opinions will vary. Currently Code::Blocks discourages this form by supporting the other two and not it. Encouraging those who want code completion to use the other forms. I by no means believe this to be intentional. It might simply be a bug or support simply hasn't been written yet and most users already are using the other forms of initialization and just haven't seen this use case.

As I am just learning. I am preferring to use C++11/14 idioms and best practices as much as they are understood.

Any wisdom greatly appreciated.

Thanks.

Jimmie

Offline jlhouchin

  • Single posting newcomer
  • *
  • Posts: 3
Re: Code Completion for brace initialization style
« Reply #1 on: May 15, 2014, 09:51:33 pm »
My apologies. I changed some of the code from the books examples so the above code may seem stupid. A const is not a variable. 42 is not a float. ...

kAnswer is the naming scheme I chose for constant names after reviewing some common choices. And yes, it might be different. I didn't see this exact option anywhere. :)

Let me reformat it as:

Code
// Yes I know the below in total will not compile
// as I am using the same variable names for simplicity
// I mention C++11 but do not state that it is limited to C++11 and beyond.

const float kAnswer{42.0};
// C++11 brace form initialization
// compiles fine, but no code completion

const float kAnswer = {42.0};
// C++11 brace form initialization with =
// compiles fines, has code completion

const float kAnswer(42.0);
// compiles fine, has code completion

const float kAnswer = 42.0;
// compiles fines, has code completion

Thanks again for any insight or help.

Jimmie