Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unique_ptr autocomplete in eclipse

I am playing with unique_ptr. In my last post people helped me compiling a program that used this pointer by specifying the -std=c++0x during compilation. Now i was wondering if there is any way to instruct eclipse to consider c++11 while auto-completing?
unique_ptr is not coming in the list of std:: namespace, nor I can find the methods (reset, move...) associated with a unique_ptr.

Thank you vahid

like image 881
rahman Avatar asked Oct 08 '22 08:10

rahman


2 Answers

The "memory" header (probably found at /usr/include/c++/4.9/memory) only includes "unique_ptr.h" and "shared_ptr.h" (probably found at /usr/include/c++/4.9/bits/unique_ptr.h and /usr/include/c++/4.9/bits/shared_ptr.h) if the macro "__cplusplus" is equal or greather than "201103L". Check memory.h for yourself to see the "#if" preprocessor condition there, at line 69 (or search for the string "#if __cplusplus >= 201103L").

As others mentioned, compiling with "-std=c++0x" or later c++ standards (-std=c++11 or -std=c++14) solves the compilation errors, but not the eclipse indexing and autocomplete problem.

To solve the eclipse indexing issue I added the "__cplusplus" Preprocessor Macro to the project build properties, with the value "201103L", and afterwards I refreshed the index;

To add the preprocessor macro:

"right click the project on project explorer" >> properties >> C/C++ General >> Preprocessor Includes >> Entries >> GNU C++ >> CDT User Settings Entries >> Add... >> Preprocessor Macro;

Then entry a macro with name "__cplusplus" and value "201103L";

Afterwards, to refresh the index, do:

"right click project on project explorer" >> Index >> Rebuild;

Ps.: I was using gcc 4.9.2 and eclipse Luna (4.4.2), on ubuntu 15.04 64bits

like image 130
gnumaru Avatar answered Oct 17 '22 03:10

gnumaru


I guess you should add __GXX_EXPERIMENTAL_CXX0X__ definition to your "Paths and Symbols" in Eclipse. See also this question GNU C++ how to check when -std=c++0x is in effect? and the same question Eclipse indexer can't resolve shared_ptr for shared_ptr.

like image 1
ks1322 Avatar answered Oct 17 '22 02:10

ks1322