c++14

How to define a static constexpr matrix in c++14?

牧云@^-^@ 提交于 2019-12-11 07:48:53
问题 I am currently using C++14. I would like to define a Matrix class which I can use for defining runtime matrices, but also constexpr matrices. I also would like to define static constexpr matrices based on such a class. I consider this as a starting point for the Matrix class. Then I would like to write something as: static constexpr Matrix<double,2,2> staticmat{0.1,0.2,0.3,0.4}; so that staticmat is constexpr and unique, being static. However, in order to initialise this, I would need a

C++14 auto deduction error: function returns an array

本秂侑毒 提交于 2019-12-11 07:29:41
问题 community! I'm trying to apply new C++14 features and unexpectedly encountered on error while I was attempting to pass the const char[] argument to the function given below: decltype(auto) autofunc( const auto& a) { cout<<"Hello World\n"; cout<<a<<endl; } auto lambd = [](const auto& word){ autofunc(std::forward< decltype(word) > (word));}; int main() { lambd("Goodbye World\n"); return 0; } I don't know why,but the compilier's message is that function tries to return an array (why would it do

converting parameter pack into a vector

跟風遠走 提交于 2019-12-11 07:23:49
问题 I am trying to understand variadic templates in C++ and I am lost in the following example: Imagine a function foo(T, T, T, T) which takes variadic number of arguments of the same type T and converts them into a vector. Any idea how to implement one? It should work like this foo<int>(1,2,3,4) returns std::vector<int> x{1,2,3,4} foo<double>(0.1,0.2,0.3) returns std::vector<double> x{0.1,0.2,0.3} 回答1: If the T values as known at compile-time, you can pass they as template parameters and write

Boost-range not working with C++1y init-capture mutable lambda

百般思念 提交于 2019-12-11 06:55:58
问题 I want to compute the element-wise difference of two vectors using Boost.Range and C++1y lambdas with init-capture . The simpler case of subtracting a fixed (i.e. the first) element of one vector works. However, when I try to compute the "vectorized difference" by increasing the iterator over the second range (and making the lambda mutable ), I get a compiler error. Sample code (note that I didn't use generalized lambdas so that both g++ 4.8 and Clang SVN can parse this code): #include

While testing SFINAE, I found something that I don't think should work

爷,独闯天下 提交于 2019-12-11 06:55:50
问题 I found an interesting conditional function exclusion that I got from this site and while testing it I came across this: #include<type_traits> namespace detail { enum enabler {}; } template <int overload, typename Condition> using EnableIf = std::enable_if_t<Condition::value, detail::enabler>; template <typename T, EnableIf<0, std::is_same<T, int>>...> T twice(T t) { return 2 * t; } template <typename T, EnableIf<0, std::is_same<T, float>>...> T twice(T t) { return 2 * t; } int main() { twice

How to build a custom macro that behaves differently when used as constexpr (like assert)?

旧城冷巷雨未停 提交于 2019-12-11 06:19:12
问题 Starting in C++14, the assert macro can be used in functions even when they are defined as constexpr. I know this has to do with the fact that it evaluates to "true", but I'm having trouble figuring out what the actual code looks like. Specifically, how do you build a macro that prints something when run in a constexpr function that is being evaluated at run time, but shuts this non-constexpr behavior off when in a constexpr function that is being evaluated at compile time. 来源: https:/

Creating a list of objects containing std::atomic

非 Y 不嫁゛ 提交于 2019-12-11 06:02:15
问题 I have a list of objects stored in a list that represent chunks of read-only memory for threads to use. each chunk object has an atomic that acts as a reference count, pretty simple. I have a problem though, std::list<Type> apparently needs a copy constructor for Type ?, and having an std::atomic as a member of Type deletes the default copy constructor of the chunk object's class. I'm pretty sure a list isn't allowed to copy or move it's elements around whatsoever in memory, so why would it

C++14 Syntax in Eclipse CDT compiles but marked as syntax error (indexer)

三世轮回 提交于 2019-12-11 05:58:19
问题 Eclipse CDT gives me a syntax error for a valid C++14 syntax. Everything compiles and runs but the syntax highlighting is broken. I have MinGW and Eclipse running. The C++14 program compiles and executes but I get incorrect syntax highlighting / syntax checking. Here is my source code: #include <iostream> auto main() -> int { //Binary Literals C++14 with Digit separators C++14 auto seven = int{0b0000'0111}; std::cout << seven << std::endl; std::cout << __cplusplus << std::endl; return int{0};

nlohmann json ambiguous overload for 'operator='

情到浓时终转凉″ 提交于 2019-12-11 05:48:54
问题 I'm getting this compilation error with the following code #include <iostream> #include <boost/optional.hpp> #include "nlohmann_json.hpp" namespace nlohmann { template <typename T> struct adl_serializer<boost::optional<T>> { static void to_json(json& j, const boost::optional<T>& opt) { if (opt == boost::none) j = nullptr; else j = *opt; } static void from_json(const json& j, boost::optional<T>& opt) { if (j.is_null()) opt = boost::none; else opt = j.get<T>(); } }; } int main(int argc, char*

osx - C++14 compiler not detected, multiple versions of gcc when compiling graph-tool in anaconda

不羁岁月 提交于 2019-12-11 05:35:24
问题 My ultimate goal is to get python package graph_tool working on my system and also on ipynb if possible. I have already brew install graph-tool , as indicated here, but that's still insufficient. So I follow conda instructions here, and I make decent progress, until I encounter a compiler issue with the configuration. $ conda create -n py36env python=3.6.3 anaconda (py36env) $ conda install -c conda-forge cgal ... and so forth with the other required libraries (py36env) Tams-MacBook-Pro:graph