c++14

exception cleanup error on gcc 6.3 with C++14

房东的猫 提交于 2020-02-05 06:31:10
问题 I am trying to compile C++14 project of mine with gcc 6.3 and I am getting: hm3/pairblob.cc: In static member function 'static std::unique_ptr<hm3::PairBlob> hm3::PairBlob::create(const hm3::PairBlob*)': hm3/pairblob.cc:64:44: error: exception cleanup for this placement new selects non-placement operator delete [-fpermissive] std::unique_ptr<PairBlob> pair{ new(size) PairBlob }; ^~~~~~~~ In file included from /usr/include/c++/6.3.1/ext/new_allocator.h:33:0, from /usr/include/c++/6.3.1/armv7l

Swig C++: Interfacing vector<Class object *>

家住魔仙堡 提交于 2020-02-01 21:34:19
问题 basically I am trying to have a tuple/list which contains a dictionary of different data types of values(float/int/bool/char/list) in python. I am getting this from the following code: (<f_p.Bunch; proxy of <Swig Object of type 'Bunch *' at 0x7f4954bdde10> >, <f_p.Bunch; proxy of <Swig Object of type 'Bunch *' at 0x7f4954bdde40> >, <f_p.Bunch; proxy of <Swig Object of type 'Bunch *' at 0x7f495668be70> >, <f_p.Bunch; proxy of <Swig Object of type 'Bunch *' at 0x7f4952d09a50> >) I want to get

What is the purpose of marking the set function (setter) as constexpr? [duplicate]

大兔子大兔子 提交于 2020-02-01 17:41:07
问题 This question already has answers here : What is the use of a constexpr on a non-const member function? (2 answers) Closed 12 months ago . I cannot understand the purpose of marking the setter function as constexpr , that is allowed since C++14. My misunderstanding comes from the next situation: I declare a class with a constexpr c-tor, and I am about to use it in a constexpr context, by creating a constexpr instance of that class constexpr Point p1 . An object p1 now is constant and its

Bind metafunction: accept both types and template template parameters (accept anything)

拥有回忆 提交于 2020-02-01 05:33:05
问题 I'm trying to write a Bind metaprogramming template helper metafunction that binds a template parameter to something. I have a working implementation for simple template metafunctions: template<typename T0, typename T1> struct MakePair { using type = std::pair<T0, T1>; }; template<template<typename...> class TF, typename... Ts> struct Bind { template<typename... TArgs> using type = TF<Ts..., TArgs...>; }; using PairWithInt = typename Bind<MakePair, int>::type; static_assert(std::is_same

Why doesn't c++ have a specified order for evaluating function arguements?

三世轮回 提交于 2020-02-01 04:29:26
问题 It seems to me that it's a very basic and necessary feature of any functional programming language to know the order in which the arguments of a function call will be evaluated. Am I wrong in this? Why doesn't C++ define this? Is it being discussed for any future version of C++? 回答1: Why doesn't C++ do it this way? For starters, C++ isn't a functional programming language. And the fastest way to evaluate the arguments depends on the implementation and architecture, so the compiler gets to

Should I compare a std::string to “string” or “string”s?

一世执手 提交于 2020-01-30 14:15:52
问题 Consider this code snippet: bool foo(const std::string& s) { return s == "hello"; // comparing against a const char* literal } bool bar(const std::string& s) { return s == "hello"s; // comparing against a std::string literal } At first sight, it looks like comparing against a const char* needs less assembly instructions 1 , as using a string literal will lead to an in-place construction of the std::string . ( EDIT: As pointed out in the answers, I forgot about the fact that effectively s

Should I compare a std::string to “string” or “string”s?

烈酒焚心 提交于 2020-01-30 14:15:39
问题 Consider this code snippet: bool foo(const std::string& s) { return s == "hello"; // comparing against a const char* literal } bool bar(const std::string& s) { return s == "hello"s; // comparing against a std::string literal } At first sight, it looks like comparing against a const char* needs less assembly instructions 1 , as using a string literal will lead to an in-place construction of the std::string . ( EDIT: As pointed out in the answers, I forgot about the fact that effectively s

Should I compare a std::string to “string” or “string”s?

与世无争的帅哥 提交于 2020-01-30 14:15:27
问题 Consider this code snippet: bool foo(const std::string& s) { return s == "hello"; // comparing against a const char* literal } bool bar(const std::string& s) { return s == "hello"s; // comparing against a std::string literal } At first sight, it looks like comparing against a const char* needs less assembly instructions 1 , as using a string literal will lead to an in-place construction of the std::string . ( EDIT: As pointed out in the answers, I forgot about the fact that effectively s

Why generic lambdas are allowed while nested structs with templated methods aren't?

∥☆過路亽.° 提交于 2020-01-30 04:04:31
问题 As far as I understand - generic lambdas are transformed into objects of local scope structs with templated operator() . This makes generic lambda very powerful and easy to use tool. On the other hand one can create structs nested into the function, when however the struct has templated member e.g.: #include <iostream> int main() { struct inner { template <class T> void operator()(T &&i) { } }; return 0; } or is templated by itself: int main() { template <class T> struct inner { void operator

std::move or std::forward when assigning universal constructor to member variable in C++

ぃ、小莉子 提交于 2020-01-29 10:44:25
问题 Consider the following classes foo1 and foo2 template <typename T> struct foo1 { T t_; foo1(T&& t) : t_{ std::move(t) } { } }; template <typename T> struct foo2 { foo1<T> t_; foo2(T&& t) : t_{ std::forward<T>(t) } { } }; Is it always the case that the constructor of foo1 represents the correct way to initialise the member variable T ? i.e. by using std::move . Is it always the case that the constructor of foo2 represents the correct way to initialise the member variable foo1<T> due to needing