Questions tagged [c++11]

29023 questions
1

votes
0

answer
55

Views

template substitution failure with sfinae

The following code does not compiler with GCC 5.2 or later, have not tried older compiler. Amy idea on what I am doing wrong here. #include #include #include template typename std::enable_if::type operator^=(T &lhs, const T &rhs) { lhs = static_cast( static_cast(lhs) ^ static_cast(rhs)); return...
Sameer Varyani
1

votes
0

answer
66

Views

Copy constructor called on object instantiation

I may just be miss reading this code but in my attempt to call the default constructor, the code instead calls the copy constructor on my proposed creation. Could someone give me a knowledge bomb on where my mental model and this code done meet :-/ Below is the code written, its a rough outline fo...
Theko Lekena
1

votes
1

answer
85

Views

Unable to compile LLVM 5.0.0 with MSVC 14.0

I am trying to compile LLVM 5.0.0 from source on Windows 10 with Visual Studio 14.0 (2015). I used the following cmake flags: CMAKEOPTIONS += -D PYTHON_EXECUTABLE:PATH=$(PYTHON_PATH)/bin/python CMAKEOPTIONS += -D LLVM_ENABLE_TERMINFO=0 CMAKEOPTIONS += -D LLVM_ENABLE_EH=1 CMAKEOPTIONS += -D LLVM_ENA...
Ashish Uthama
1

votes
1

answer
36

Views

C++ interactive command line prompt without waiting for a newline character

Is there a way to process command line input before seeing the newline character? I'm thinking of making a program that supports autocomplete (like the ones found in search engines or iOS keyboard). To be more specific, my program will prompt for user input when started, and for each character input...
minjoo lim
1

votes
3

answer
175

Views

overloading [] and , c++11

So suppose we have this expression auto x =Object.operator[][1,2,3,4]; I want my C++ code to insert the numbers 1 2 3 4 to a vector that is located inside the object my code is below. class Object{ Object operator[](int temp){ this->x.push_back(temp); return *this; } vector x; }; int main() { auto...
Nick Hughes
1

votes
0

answer
107

Views

HashMap with std::future as the key

Since we cannot get the arguments from std::future, I am trying to maintain a map between std::future and std::string. The following statement: std::unordered_map map fails with the following error: error: no match for call to '(const std::hash) (const std::future&)'...
UnderWood
1

votes
0

answer
193

Views

Returning thread-local data from a shared library C-api

Question 1: Is it safe and portable to return a pointer to a thread_local data from a shared library providing a traditional C-API? The lib itself is naturally implemented with C++11. Safetyness in respect to memory leaks and race conditions, portablitity covering the main desktop OSs: Windows, Lin...
Strueddalfie
1

votes
0

answer
129

Views

std::map::insert with C++17 calling copy constructor of pair with non copyable types

I get an error saying that the compiler is trying to use std::pair's copy constructor with std::map in the following code #include #include #include using std::cout; using std::endl; class Something { public: Something(const Something&) = delete; Something(Something&&) { cout
Curious
1

votes
1

answer
128

Views

Compiling OpenFST for iOS giving casting errors

I am trying to compile OpenFST for iOS, here is where make is failing: cd openfst-1.6.5/src/lib /Applications/Xcode.app/Contents/Developer/usr/bin/g++ -DHAVE_CONFIG_H -I./../include -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/c+...
Anx8
1

votes
1

answer
34

Views

Why is this regex match failing [duplicate]

This question already has an answer here: Difference between std::regex_match & std::regex_search? 2 answers I am using the following code and the regex match is failing std::regex reg('^Program Files'); if(std::regex_match('Program Files (x86)',reg) { return true; } I tried this regex here and it...
Rajeshwar
1

votes
1

answer
117

Views

Variadic template taking reference to data types

I would like to create a wrapper for class methods so I used a variable template and std::tuple to wrap the method. It works as I need, but I cannot figure out how to be able to wrap a method with parameters called by reference. Please see the main function below. #include #include #include using...
vitakot
1

votes
0

answer
62

Views

std::promise in realtime context

I am developing an application with a realtime context. One of the threads that executes in realtime context dequeues Task message objects from a mailbox (with real-time capabilities). Those Task messages contain a std::promise and a command. After the thread gets the Task it executes the command an...
Finkman
1

votes
1

answer
43

Views

How can I turn on the auto matching when invoking the template explicit instantiation?

I have two template class, and the Leaf is derived from the Base, then I developed a template function which uses the reference of the Base as its parameter. And set the definition and the instantiation of that function in its source file. The issue happened once I tried to pass the Leaf as the argu...
Calvin
1

votes
0

answer
77

Views

placement new with different types in preallocated memory - how to guarantee alignment?

I'm trying to build a class that can be used as some sort of shared pointer. For performance reasons I'd like to implement a factory function that allocates the memory for the object and a unsigned int reference counter in a single step: template class SharedPointer { uint8_t* buffer; T* obj; unsign...
csk
1

votes
2

answer
310

Views

how to write a C++ class member function wrapper?

I want to wrap some class member functions and do some preparing and cleaning up work around them. I try to copy some other thread pool code but get some error I cannot deal out. How to do it correctly? #include #include using namespace std; class A { public: void connect() {}; void close() {}; te...
Liu Weibo
1

votes
0

answer
82

Views

Converting variadic template to variadic function

Given the following case: #include enum class Event { None, Resize, /*Some Other Events*/ }; template struct validator; template using eventor = typename validator::type; template struct validator { using type = void(*)(unsigned int, unsigned int); }; struct My_Event { unsigned int size; void** fun...
Juan
1

votes
0

answer
32

Views

Implementing SIGEV_THREAD in Solaris10.

As we Know SIGEV_THREAD not supported by Solaris 10, But I need this for my task Scheduler in Solaris 10. So i took the code of timer_create.c from google and all other required file also. so now I am trying to compile my code, given below errow i got: bash-3.2$ g++ -I./ -std=c++11 -o sol10 *.cpp Un...
Ram
1

votes
0

answer
732

Views

Disable C++11 in Qt Creator

How can I disable C++11/14 in Qt Creator? I'd like to compile my project as C++98/03 code. By default it ran gcc like this: g++ ... -std=gnu++11 -Wextra ... I edited *.pro file so it contains the following: ... CONFIG -= c++11 CONFIG += no-c++11 no-c++14 QMAKE_CXXFLAGS += -std=c++98 -pedantic ......
Konstantin T.
1

votes
1

answer
138

Views

C++ template meta progr. conditional memory allocation

I am trying to implement a simple Linear-Algebra library (for learning purposes). Problem => I would like the Matrix template class to either declare a fixed-size array at compile time, or use dynamic memory allocation if the number of Rows and Columns are not yet known. How can i effectively / cor...
Leo G.
1

votes
0

answer
68

Views

Getting a c++11 library on an older version of c++?

A remote machine that I don't own uses gcc 4.1.2 (2007 or so). I'd like to use the random library and its functions, which comes with the c++11 standard. Is there some way I can use the contents of ? Can I dump all of into a custom header? I lack understanding of libraries and wonder if there's a...
A Ton
1

votes
0

answer
110

Views

#define constexpr in C++

I came across some code as shown below: #define set_opcode(name) \ constexpr static auto get_opcode() noexcept \ { \ return OpcodeValue::name; \ //OpcodeValue is some enum } class NoopOpcode : public Opcode { public: set_opcode(NOOP); std::string serialize() const noexcept override; bool deserialize...
JJTO
0

votes
0

answer
5

Views

File data read to map, but map::find() doesn't work

I need to find a key/value pair in a map, but due to how the map is populated, for some reason map::find() doesn't work. The data it reads from can be boiled down to Key1,a,b,c Key2,a Key3 Key4,a,b With this, I could print out all this data using an iterator loop, but map::find() does not work with...
Caleb
1

votes
0

answer
122

Views

Using c++11 legacy library in a C++17 project: compiler & linker problems

I am working in a project based on C++17 and have to rely on a library built with C++11 (or older). Problems arise from the fact that several structs have been removed for good from std with C++17. Note that I am building the legacy library from source! The problems: If I am building the library wit...
B M
1

votes
0

answer
920

Views

How to wrap a library(with c++11 feature) in CGO

My OS is Mac and the compiler is clang I want to wrap a C++ library (openfst , which uses C++11 feature ) in Go I follow the method of Scott Wales in How to use C++ in Go? , and the demo given by him works well( and no need to write makefile) First write a C wrapper for the C++ library. Use cgo to i...
chao.yang
1

votes
0

answer
121

Views

Linking a program to libraries the use different _GLIBCXX_USE_CXX11_ABI each

I am trying to compile a program (using GCC 5.4.O) that depends on two libraries. Library A was compiled using the old ABI, while library B was compiled using the new C++11 ABI (see Dual ABI). If compile the program setting _GLIBCXX_USE_CXX11_ABI 1, I have linking errors with library A. If I set it...
toliveira
1

votes
0

answer
160

Views

C++ set wants an initializer_list when I try to add a single number

I have a problem that would seem not a lot of people run into. I'm not sure if it's blatantly obvious what to do and I'm not getting it, or I am writing something wrong. I'm using Windows 10, Android Studio. my code segment looks like this. vector vpLatSortedNodes; vector vpLonSortedNodes; //The ab...
Johnk
1

votes
0

answer
77

Views

C++ weird usage of new keyword [duplicate]

This question already has an answer here: What uses are there for “placement new”? 22 answers What is an in-place constructor in C++? [duplicate] 6 answers I was trying to learn something else then i encounter with the following code. class point{}; point p_; new (&p_) point(w.p_); What does...
TuttyFruty
1

votes
1

answer
177

Views

Installing ceres-solver on iOS

running cmake -DCMAKE_TOOLCHAIN_FILE=ceres-solver/cmake/iOS.cmake -DCMAKE_CXX_FLAGS='-stdlib=libc++' -DEIGEN_INCLUDE_DIR=/usr/local/Cellar/eigen -DIOS_PLATFORM=OS ceres-solver gives me these errors -- Using minimal glog substitute (include): internal/ceres/miniglog -- Max log level for minimal glo...
Wy th
1

votes
0

answer
143

Views

libsourcey & OpenCV stream example

I am trying to make a second annotated web based video screen for our security cams. Basicly we are tooling the opencv with C++11 , based solution to boxing/ovelays for important objects in the video frames . We can see locally with imshow . We want to stream this frames so we can access through we...
2adnielsenx xx
1

votes
0

answer
76

Views

How can I serialize std::vector<details> (details is a struct.)

I have a struct in c++11 , like: struct objectv1 { matrix obj_descriptor; string person_name; matrix p_obj_chip; string notes; }; and than: std::vector object_deteails; and pushing back to object_details data. How can I serialize and deserialize the object_details vector? It could be helpfull for b...
2adnielsenx xx
1

votes
1

answer
62

Views

How do I use an enum declared in a class in that same class's base's template

Sorry for the wordy/overlong question, but I don't know how else to word this. I have a class. This class extends a base class that is templated. I want to use an enum that is declared in the derived class as one of the template arguments. Not a value from it, the actual enum, although I doubt this...
ProgramGamer
1

votes
1

answer
52

Views

Skip intermediate classes in hierarchy inheritance with boost::serialization

Context: I have a tree-like structure representing a AST of Expr that I want to serialize using boost::serialization. The main issue is that all classes have non default constructors and const children. To overcome this issue, I followed the doc and overloaded load_construct_data and save_construct...
Davidbrcz
1

votes
1

answer
117

Views

How to write a factory function to initialize a constexpr reference in C++?

I want to initialize a constexpr reference by a factory function, but I failed to succeed. #include using namespace std; struct IWorker // common interface of workers { virtual void foo() const = 0; }; template // example worker struct Worker : IWorker { T& Target; const T Source; constexpr Worker...
Marcel
1

votes
1

answer
43

Views

vector of boost::function not working with _placeholder

I need your help. I tried a lot to find a solution for the problem but failed so far. Idea: Create a vector of 'command tuples' like the following: typedef boost::tuple command_tuple; std::vector commands { boost::make_tuple('command1', boost::bind(&myclass::command1, this)) }; If the string 'comman...
drtyhlpr
1

votes
0

answer
81

Views

C++ Inheritance that throws a expected class-name before '{' token

I keep getting the following error and I am not sure why. After some googling I still do not have a solution. I included the files below so that hopefully you all can see something that I can't. Error: expected class-name before '{' token class LinkedList: public ListInterface{ LinkedList.h: #ifndef...
Kyle Kappes-Sum
1

votes
0

answer
29

Views

c++ segmentation error using a string variable

I uploaded whole code because i cannot pinpoint the exact location of segmentation error since the segmentation error is a vague error #include #include #include #include #include using namespace std; bool newl=false; string censormode (string line){ int len=line.length(); int end; string word...
jeff wright
1

votes
1

answer
284

Views

Replacing #pragma omp atomic with c++ atomics

I'm replacing some OpenMP code with standard C++11/C++14 atomics/thread support. Here is the OpenMP minimal code example: #include #include void omp_atomic_add(std::vector const& rows, std::vector const& cols, std::vector& values, std::size_t const row, std::size_t const col, double const value)...
fast asleep
1

votes
0

answer
101

Views

why is my code and data segments in one elf64-x86-64 elf readelf

readelf -e output is below. Notice that my code and data segments are rolled into one? How is this being done? Can I disable it? I'm using openSuse 42.2 which is a 64-bit OS. I'm running out of ideas, I've searched everywhere. The only reference I can find is via this website https://timothylottes.g...
Winston Ang
1

votes
1

answer
69

Views

Parameter pack and member function pointer type deduction

I have a little issue with clang and parameter packages. The clang version is: Apple LLVM version 9.0.0 (clang-900.0.38) Target: x86_64-apple-darwin16.7.0 Thread model: posix I have a problem I managed to reproduce in the following snippet: class Foo{ public: int fIsOk; bool fIsNotOk; bool fTheThird...
jetstream
1

votes
0

answer
64

Views

Forward parameter pack to pointer function (unknown types)

I am trying to write an es6 Promise-like class for c++ without the use of an external library (in my project I can't use boost or the std lib). I am having troubles handling the callback that's supposed to process a resolved or rejected promise. Because I want to chain different resolved value types...
Shane van den Bogaard

View additional questions