c++11

Identifying temporary object creation in Eigen

半腔热情 提交于 2021-02-19 06:51:42
问题 As the documentation in Eigen C++ library points out at many places, to get the maximum performance in terms of the computation time, we need to avoid temporary objects as far as possible. In my application, I deals with Dynamic size matrices. I would like to know the creation of temporary matrices in my calculations. Is there any general method to identify the creation of the temporary matrices? For example, Eigen::MatrixXf B, C, D; ....some initialization for B, C, D Eigen::MatrixXf A = B*C

Using -std=c++11 on VS2015

孤人 提交于 2021-02-19 05:56:18
问题 I have created a shared object for Android in Visual Studio 2015 . It works fine so far, but pop_back() for a wstring does not work: wstring element = "JustATest!"; if (element.back() == L'!') { element.pop_back(); } VS2015 tells me: " no member named 'pop_back' in 'std::basic_string<wchar_t>' ". Can anybody tell me how to get rid of this error? I have no idea why this should not work. Is that because for some reason VS2015 does not use C++11 here? Thank you for the help! Edit: Another error:

A container of std::function with polymorphic types as function arguments

我与影子孤独终老i 提交于 2021-02-19 05:22:17
问题 I would like to have "yet another" callback registration stuff. Different event types extending a common base event type will trigger associated callback functions. here is the initial draft or idea #include <functional> #include <iostream> #include <unordered_map> class BaseEvent { public: virtual ~BaseEvent() {} }; class DerivedEvent_1 : public BaseEvent {}; class DerivedEvent_2 : public BaseEvent {}; // a container holding callback functions std::unordered_map<size_t/*event*/, std:

Pass a C++ member function to a C function

落爺英雄遲暮 提交于 2021-02-19 05:17:32
问题 We have a structure that accepts C function pointers: int one(int x) { } int two(int x) { } struct Cstruct { int (*fn1)(int); int (*fn2)(int); }; Now I have a C++ class that has below methods: class A { public: int one(int x) { } int two(int x) { } int three(int x) { struct Cstruct cstr = {&this->one, &this->two}; } }; While trying to initialize class A methods address to a instance of Cstruct compiler is giving error of an invalid conversion? How can I assign the Class member function

Eliminating instantiation of useless destructor calls?

浪尽此生 提交于 2021-02-19 04:08:35
问题 Well, my colleague is pretty in depth nitpicking about eliminating unnecessarily code instantiations for destructor functions. Still same situation, as mentioned in this question: Very limited space for .text section (less 256 KB) Code base should scale among several targets, including the most limited ones Well known use cases of the code base by means some destructor logic is neccesary to manage object lifetimes or not (for many cases life-time of objects is infinite, unless the hardware is

Eliminating instantiation of useless destructor calls?

时间秒杀一切 提交于 2021-02-19 04:06:08
问题 Well, my colleague is pretty in depth nitpicking about eliminating unnecessarily code instantiations for destructor functions. Still same situation, as mentioned in this question: Very limited space for .text section (less 256 KB) Code base should scale among several targets, including the most limited ones Well known use cases of the code base by means some destructor logic is neccesary to manage object lifetimes or not (for many cases life-time of objects is infinite, unless the hardware is

Passing an integer or a type as a template parameter?

邮差的信 提交于 2021-02-19 03:12:58
问题 Here is an example case of what I'm trying to do (it is a "test" case just to illustrate the problem) : #include <iostream> #include <type_traits> #include <ratio> template<int Int, typename Type> constexpr Type f(const Type x) { return Int*x; } template<class Ratio, typename Type, class = typename std::enable_if<Ratio::den != 0>::type> constexpr Type f(const Type x) { return (x*Ratio::num)/Ratio::den; } template</*An int OR a type*/ Something, typename Type> constexpr Type g(const Type x) {

Passing an integer or a type as a template parameter?

冷暖自知 提交于 2021-02-19 03:12:49
问题 Here is an example case of what I'm trying to do (it is a "test" case just to illustrate the problem) : #include <iostream> #include <type_traits> #include <ratio> template<int Int, typename Type> constexpr Type f(const Type x) { return Int*x; } template<class Ratio, typename Type, class = typename std::enable_if<Ratio::den != 0>::type> constexpr Type f(const Type x) { return (x*Ratio::num)/Ratio::den; } template</*An int OR a type*/ Something, typename Type> constexpr Type g(const Type x) {

Passing an integer or a type as a template parameter?

做~自己de王妃 提交于 2021-02-19 03:10:50
问题 Here is an example case of what I'm trying to do (it is a "test" case just to illustrate the problem) : #include <iostream> #include <type_traits> #include <ratio> template<int Int, typename Type> constexpr Type f(const Type x) { return Int*x; } template<class Ratio, typename Type, class = typename std::enable_if<Ratio::den != 0>::type> constexpr Type f(const Type x) { return (x*Ratio::num)/Ratio::den; } template</*An int OR a type*/ Something, typename Type> constexpr Type g(const Type x) {

scope of std::lock_guard inside if block

一个人想着一个人 提交于 2021-02-19 02:37:39
问题 Currently studying about std::mutex and would love some help. If I've a code that looks like - .... if(returnBoolValue()) { std::lock_guard<std::mutex> lock(mutex_var); .... .... } .... is the std::lock_guard guarding the function returning the value inside if condition? ie. returnBoolValue() And how should I improve it so that function call is inside the guard as well, if possible? std::mutex - http://en.cppreference.com/w/cpp/thread/mutex std::lock_guard - http://en.cppreference.com/w/cpp