C++ unordered_map move beginner error - c++11
Sorry for the noob question here, but i don't even know what to search on google. I tried some documention on the move semantic but i still can't solve my problem.
So if somebody can give me some clues, i'll be really thanksfull.
About the code:
graph.hpp:
#ifndef GRAPH_HPP
#define GRAPH_HPP
#include <cstdlib>
#include <unordered_map>
#include <vector>
#include <string>
template<typename T, typename U>
class Link;
template<typename T, typename U>
class Node;
namespace graph
{
template<typename T, typename U>
class Link
{
public:
Link() = default;
Link(U&& data, T& node) : _data(data), _endNode(node) {}
~Link() = default;
private:
U _data;
Node<T, U>& _endNode;
};
template<typename T, typename U>
class Node
{
public:
Node() = default;
Node(T&& data) : _data(data) {};
~Node() = default;
private:
T _data;
std::vector<Link<T, U>> _links;
};
template<typename K, typename T, typename U>
class Graph
{
public:
Graph() = default;
~Graph() = default;
private:
size_t _nbNode;
std::unordered_map<K, Node<T, U>> _nodes;
public:
#include "graph.tpp"
};
}
#endif
graph.tpp:
void add_Link(const K& key1,
const K& key2,
U&& linkInfo)
{
if (!_nodes.count(key1)
|| !_nodes.count(key2))
throw "Key doesn't exist!";
Link<T, U> newLink(linkInfo, _nodes[key2]);
_nodes[key1].links.push_back(newLink);
}
void add_Node(K& key, T&& elem)
{
Node<T, U> newNode(std::move(elem));
_nodes[key] = std::move(newNode);
}
main.cpp:
#include "graph.hpp"
#include <string>
int main()
{
std::string name("name");
graph::Graph<std::string, std::string, std::string> graph;
graph.add_Node(name, "lol");
return 0;
}
I just want to add a new element in the unordered_map with a move. But it's just say me :
clang++ -Wall -Wextra -std=c++14 -O2 -march=native -s -fomit-frame-pointer -c src/test.cpp -o obj/test.o -I ./src/include -I ./src/template/
clang: warning: argument unused during compilation: '-s'
In file included from src/test.cpp:1:
In file included from ./src/include/graph.hpp:15:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/unordered_map:41:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/tuple:39:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/array:38:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/stdexcept:39:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/string:40:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/char_traits.h:39:
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_algobase.h:336:18: error: object of type 'graph::Link<std::basic_string<char>, std::basic_string<char> >' cannot be assigned because its copy
assignment operator is implicitly deleted
*__result = *__first;
^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_algobase.h:396:36: note: in instantiation of function template specialization 'std::__copy_move<false, false,
std::random_access_iterator_tag>::__copy_m<const graph::Link<std::basic_string<char>, std::basic_string<char> > *, graph::Link<std::basic_string<char>, std::basic_string<char> > *>' requested here
_Category>::__copy_m(__first, __last, __result);
^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_algobase.h:432:23: note: in instantiation of function template specialization 'std::__copy_move_a<false, const graph::Link<std::basic_string<char>,
std::basic_string<char> > *, graph::Link<std::basic_string<char>, std::basic_string<char> > *>' requested here
return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_algobase.h:464:20: note: in instantiation of function template specialization 'std::__copy_move_a2<false, __gnu_cxx::__normal_iterator<const
graph::Link<std::basic_string<char>, std::basic_string<char> > *, std::vector<graph::Link<std::basic_string<char>, std::basic_string<char> >, std::allocator<graph::Link<std::basic_string<char>, std::basic_string<char> > > > >,
__gnu_cxx::__normal_iterator<graph::Link<std::basic_string<char>, std::basic_string<char> > *, std::vector<graph::Link<std::basic_string<char>, std::basic_string<char> >, std::allocator<graph::Link<std::basic_string<char>,
std::basic_string<char> > > > > >' requested here
return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/vector.tcc:206:27: note: in instantiation of function template specialization 'std::copy<__gnu_cxx::__normal_iterator<const
graph::Link<std::basic_string<char>, std::basic_string<char> > *, std::vector<graph::Link<std::basic_string<char>, std::basic_string<char> >, std::allocator<graph::Link<std::basic_string<char>, std::basic_string<char> > > > >,
__gnu_cxx::__normal_iterator<graph::Link<std::basic_string<char>, std::basic_string<char> > *, std::vector<graph::Link<std::basic_string<char>, std::basic_string<char> >, std::allocator<graph::Link<std::basic_string<char>,
std::basic_string<char> > > > > >' requested here
std::_Destroy(std::copy(__x.begin(), __x.end(), begin()),
^
./src/include/graph.hpp:40:10: note: in instantiation of member function 'std::vector<graph::Link<std::basic_string<char>, std::basic_string<char> >, std::allocator<graph::Link<std::basic_string<char>, std::basic_string<char> > >
>::operator=' requested here
class Node
^
src/test.cpp:9:9: note: in instantiation of member function 'graph::Graph<std::basic_string<char>, std::basic_string<char>, std::basic_string<char> >::add_Node' requested here
graph.add_Node(name, "lol");
^
./src/include/graph.hpp:36:15: note: copy assignment operator of 'Link<std::basic_string<char>, std::basic_string<char> >' is implicitly deleted because field '_endNode' is of reference type
'Node<std::basic_string<char>, std::basic_string<char> > &'
Node<T, U>& _endNode;
^
In file included from src/test.cpp:1:
In file included from ./src/include/graph.hpp:15:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/unordered_map:41:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/tuple:39:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/array:38:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/stdexcept:39:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/string:40:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/char_traits.h:39:
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_algobase.h:336:18: error: object of type 'graph::Link<std::basic_string<char>, std::basic_string<char> >' cannot be assigned because its copy
assignment operator is implicitly deleted
*__result = *__first;
^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_algobase.h:396:36: note: in instantiation of function template specialization 'std::__copy_move<false, false,
std::random_access_iterator_tag>::__copy_m<graph::Link<std::basic_string<char>, std::basic_string<char> > *, graph::Link<std::basic_string<char>, std::basic_string<char> > *>' requested here
_Category>::__copy_m(__first, __last, __result);
^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_algobase.h:432:23: note: in instantiation of function template specialization 'std::__copy_move_a<false, graph::Link<std::basic_string<char>,
std::basic_string<char> > *, graph::Link<std::basic_string<char>, std::basic_string<char> > *>' requested here
return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_algobase.h:464:20: note: in instantiation of function template specialization 'std::__copy_move_a2<false, graph::Link<std::basic_string<char>,
std::basic_string<char> > *, graph::Link<std::basic_string<char>, std::basic_string<char> > *>' requested here
return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/vector.tcc:211:13: note: in instantiation of function template specialization 'std::copy<graph::Link<std::basic_string<char>, std::basic_string<char> >
*, graph::Link<std::basic_string<char>, std::basic_string<char> > *>' requested here
std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
^
./src/include/graph.hpp:40:10: note: in instantiation of member function 'std::vector<graph::Link<std::basic_string<char>, std::basic_string<char> >, std::allocator<graph::Link<std::basic_string<char>, std::basic_string<char> > >
>::operator=' requested here
class Node
^
src/test.cpp:9:9: note: in instantiation of member function 'graph::Graph<std::basic_string<char>, std::basic_string<char>, std::basic_string<char> >::add_Node' requested here
graph.add_Node(name, "lol");
^
./src/include/graph.hpp:36:15: note: copy assignment operator of 'Link<std::basic_string<char>, std::basic_string<char> >' is implicitly deleted because field '_endNode' is of reference type
'Node<std::basic_string<char>, std::basic_string<char> > &'
Node<T, U>& _endNode;
^
2 errors generated.
Makefile:43: recipe for target 'obj/test.o' failed
make: *** [obj/test.o] Error 1
Sorry for the trouble, have a nice day.
Okay. The problem is in this line:
_nodes[key] = std::move(newNode);
You are trying to move-assign Node<T, U>. However, Node will not have a move assignment operator implicitly declared as defaulted because there is a user-declared destructor:
~Node() = default;
As a result, that line actually calls the copy assignment operator of Node<T, U>, which performs a member-wise copy. One of the members of Node<T, U> is of type std::vector<Link<T, U>>, where Link<T, U> has a member variable that is a reference. References aren't copy-assignable, so the copy assignment operator is implicitly deleted. Hence, there is no copy assignment operator found, so the line is ill-formed.
While references aren't move-assignable either, a vector<Link<T,U>> is move-assignable, so the simplest solution is to just delete the line where you declare the destructor as defaulted:
//~Node() = default;
With that, the compiler will implicitly declare the default move constructor/assignment, and this code will do what you expect. And compile.
Side-note, this is a really bad idea:
public:
#include "graph.tpp"
};
Related
Cereal serialisation issue for std::chrono with dynamic library
I have a problem with cereal library (http://uscilab.github.io/cereal/). I have a shared library, and I would like to serialize one of its classes using cereal library. It has a member of time_point from std::chrono Here is a part of the code of my object in Event.h #include <cereal/types/chrono.hpp> #include <cereal/types/string.hpp> class Event { private: std::string m_Id; std::chrono::high_resolution_clock::time_point m_StartTime; public: template<class Archive> void serialize(Archive & archive) { archive(m_Id, m_StartTime); } The library compiles without a problem. Then I would like to use my library in an executable where I try to serialize one of the object: #include "Event.h" #include <cereal/archives/json.hpp> cereal::JSONOutputArchive output(std::cout); output(API::Event()); This code does not compile and it is complaining about the missing serialize function for the time_point. If I intend to serialize only the string it compiles. Build error output: [ 20%] Building CXX object CMakeFiles/plugin.dir/src/main.cpp.o In file included from /cereal/include/cereal/types/memory.hpp:33:0, from main.cpp:7: cereal/include/cereal/cereal.hpp: In instantiation of ‘ArchiveType& cereal::OutputArchive<ArchiveType, Flags>::processImpl(const T&) [with T = std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >; typename cereal::traits::detail::EnableIfHelper<(cereal::traits::has_invalid_output_versioning<T, ArchiveType>::value || ((! cereal::traits::is_output_serializable<T, ArchiveType>::value) && ((!(Flags & AllowEmptyClassElision)) || ((Flags & AllowEmptyClassElision) && (! std::is_empty<T>::value)))))>::type <anonymous> = (cereal::traits::detail::type)0; ArchiveType = cereal::JSONOutputArchive; unsigned int Flags = 0]’: cereal/include/cereal/cereal.hpp:347:9: required from ‘void cereal::OutputArchive<ArchiveType, Flags>::process(T&&) [with T = std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >&; ArchiveType = cereal::JSONOutputArchive; unsigned int Flags = 0]’ cereal/include/cereal/cereal.hpp:249:9: required from ‘ArchiveType& cereal::OutputArchive<ArchiveType, Flags>::operator()(Types&& ...) [with Types = {std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >&}; ArchiveType = cereal::JSONOutputArchive; unsigned int Flags = 0]’ Event.h:66:16: required from ‘void Event::serialize(Archive&) [with Archive = cereal::JSONOutputArchive]’ cereal/include/cereal/access.hpp:243:51: required from ‘static decltype (t.serialize(ar)) cereal::access::member_serialize(Archive&, T&) [with Archive = cereal::JSONOutputArchive; T = Event; decltype (t.serialize(ar)) = void]’ cereal/include/cereal/cereal.hpp:400:33: required from ‘ArchiveType& cereal::OutputArchive<ArchiveType, Flags>::processImpl(const T&) [with T = Event; typename cereal::traits::detail::EnableIfHelper<cereal::traits::has_member_serialize<T, ArchiveType>::value, (! cereal::traits::has_invalid_output_versioning<T, ArchiveType>::value), (cereal::traits::is_output_serializable<T, ArchiveType>::value && (cereal::traits::is_specialized_member_serialize<T, ArchiveType>::value || (! cereal::traits::is_specialized<T, ArchiveType>::value)))>::type <anonymous> = (cereal::traits::detail::type)0; ArchiveType = cereal::JSONOutputArchive; unsigned int Flags = 0]’ cereal/include/cereal/cereal.hpp:347:9: required from ‘void cereal::OutputArchive<ArchiveType, Flags>::process(T&&) [with T = Event; ArchiveType = cereal::JSONOutputArchive; unsigned int Flags = 0]’ cereal/include/cereal/cereal.hpp:249:9: required from ‘ArchiveType& cereal::OutputArchive<ArchiveType, Flags>::operator()(Types&& ...) [with Types = {Event}; ArchiveType = cereal::JSONOutputArchive; unsigned int Flags = 0]’ main.cpp:38:36: required from here cereal/include/cereal/cereal.hpp:462:9: error: static assertion failed: cereal could not find any output serialization functions for the provided type and archive combination. EDIT: I guess the problem is coming from the fact that the serialization function is defined in the shared library. If I just compile a test class (not in my project just for test) having an time_point it works as expected.
It looks like it was due to the order of the include. The include of the archives must be before the include of the types/chrono. So the right order is: #include <cereal/archives/json.hpp> #include "Event.h" cereal::JSONOutputArchive output(std::cout); output(API::Event());
Caffe-segnt Compilation Error
I am facing this error while compiling caffe-segnet. here is my terminal when i used ~/.local/install/caffe-segnet$ make all CXX src/caffe/layers/contrastive_loss_layer.cpp src/caffe/layers/contrastive_loss_layer.cpp: In instantiation of ‘void caffe::ContrastiveLossLayer<Dtype>::Forward_cpu(const std::vector<caffe::Blob<Dtype>*>&, const std::vector<caffe::Blob<Dtype>*>&) [with Dtype = float]’: src/caffe/layers/contrastive_loss_layer.cpp:118:1: required from here src/caffe/layers/contrastive_loss_layer.cpp:56:30: error: no matching function for call to ‘max(double, float)’ Dtype dist = std::max(margin - sqrt(dist_sq_.cpu_data()[i]), Dtype(0.0)); ^ In file included from /usr/include/c++/5/algorithm:61:0, from src/caffe/layers/contrastive_loss_layer.cpp:1: /usr/include/c++/5/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&) max(const _Tp& __a, const _Tp& __b) ^ /usr/include/c++/5/bits/stl_algobase.h:219:5: note: template argument deduction/substitution failed: src/caffe/layers/contrastive_loss_layer.cpp:56:30: note: deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘float’) Dtype dist = std::max(margin - sqrt(dist_sq_.cpu_data()[i]), Dtype(0.0)); ^ In file included from /usr/include/c++/5/algorithm:61:0, from src/caffe/layers/contrastive_loss_layer.cpp:1: /usr/include/c++/5/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare) max(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ /usr/include/c++/5/bits/stl_algobase.h:265:5: note: template argument deduction/substitution failed: src/caffe/layers/contrastive_loss_layer.cpp:56:30: note: deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘float’) Dtype dist = std::max(margin - sqrt(dist_sq_.cpu_data()[i]), Dtype(0.0)); ^ Makefile:526: recipe for target '.build_release/src/caffe/layers/contrastive_loss_layer.o' failed make: *** [.build_release/src/caffe/layers/contrastive_loss_layer.o] Error 1
Unable to compare std::chrono::duration with zero
In a template class I am working on, I want to check a precondition that a std::chrono::duration is positive, but my compiler complains that it can not instantiate the needed operator< template. Here is a minimal example (not my original container) of the problem: #include <chrono> #include <cassert> #undef NDEBUG template< typename VALUE > class Container final { public: using Interval = std::chrono::duration< unsigned int >; Container(const Interval interval_): interval(interval_), value(0) { assert(Interval::zero < interval_); } private: Interval interval; VALUE value; }; template class Container< unsigned int >; The compiler complains about the assert statement, thus: In file included from /usr/include/c++/6/cassert:44:0, from main.cpp:2: main.cpp: In constructor ‘Container<VALUE>::Container(Container<VALUE>::Interval)’: main.cpp:15:29: error: no match for ‘operator<’ (operand types are ‘std::chrono::duration<unsigned int>()’ and ‘const Interval {aka const std::chrono::duration<unsigned int>}’) assert(Interval::zero < interval_); ~~~~~~~~~~~~~~~^~~ In file included from main.cpp:1:0: /usr/include/c++/6/chrono:668:7: note: candidate: template<class _Clock, class _Dur1, class _Dur2> constexpr bool std::chrono::operator<(const std::chrono::time_point<_Clock, _Duration1>&, const std::chrono::time_point<_Clock, _Duration2>&) operator<(const time_point<_Clock, _Dur1>& __lhs, ^~~~~~~~ /usr/include/c++/6/chrono:668:7: note: template argument deduction/substitution failed: In file included from /usr/include/c++/6/cassert:44:0, from main.cpp:2: main.cpp:15:31: note: mismatched types ‘const std::chrono::time_point<_Clock, _Duration1>’ and ‘std::chrono::duration<unsigned int>()’ assert(Interval::zero < interval_); ^ In file included from main.cpp:1:0: /usr/include/c++/6/chrono:489:7: note: candidate: template<class _Rep1, class _Period1, class _Rep2, class _Period2> constexpr bool std::chrono::operator<(const std::chrono::duration<_Rep1, _Period1>&, const std::chrono::duration<_Rep2, _Period2>&) operator<(const duration<_Rep1, _Period1>& __lhs, ^~~~~~~~ /usr/include/c++/6/chrono:489:7: note: template argument deduction/substitution failed: In file included from /usr/include/c++/6/cassert:44:0, from main.cpp:2: main.cpp:15:31: note: mismatched types ‘const std::chrono::duration<_Rep1, _Period1>’ and ‘std::chrono::duration<unsigned int>()’ assert(Interval::zero < interval_); What have I done wrong? Or is this a compiler bug? My compiler is g++ (Debian 6.3.0-18+deb9u1) 6.3.0 2017051, on Debian 6.
Try with Interval::zero(). Interval::zero is a function, so you are comparing a duration with a function. As a side note, I would suggest to make your Interval argument in the constructor a template, so that you can accept other duragion scales (seconds, ms, us, etc.) template < typename Interval2 > explicit Container(const Interval2 interval_): interval(interval_), value(0) { assert(Interval2::zero() < interval_); } The std::chrono::duration constructor will adapt the tick count transparently, following both Period parameter types.
ambiguity in Assignment in FullPivHouseholder::inverse() call for 3.3.rc1
I'm running into a problem with ambiguity with an Assignment partial specialization inside the inverse method of the full-pivot Householder decomposition of a dense matrix in the first release candidate for 3.3, 3.3.rc1. Here's a minimal example that produces the error we're getting compiling the Stan math library: #include <Eigen/Dense> int main() { using Eigen::MatrixXd; MatrixXd m(2, 2); m << 1, 0, 0, 1; Eigen::FullPivHouseholderQR<MatrixXd> hh = m.fullPivHouseholderQr(); MatrixXd m_inv_transpose = hh.inverse(); } Are we not using FullPivHouseholderQR the right way? Here's the error I get using clang++ on Mac OS X (Apple LLVM version 7.0.2 (clang-700.1.81)): temp2$ clang++ -isystem ~/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1 fph.cpp In file included from fph.cpp:1: In file included from /Users/carp/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1/Eigen/Dense:1: In file included from /Users/carp/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1/Eigen/Core:389: /Users/carp/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1/Eigen/src/Core/AssignEvaluator.h:813:3: error: ambiguous partial specializations of 'Assignment, Eigen::Inverse > >, Eigen::internal::assign_op, Eigen::internal::Dense2Dense, void>' Assignment::run(actualDst, src, func); ^ /Users/carp/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1/Eigen/src/Core/PlainObjectBase.h:721:17: note: in instantiation of function template specialization 'Eigen::internal::call_assignment_no_alias, Eigen::Inverse > >, Eigen::internal::assign_op >' requested here internal::call_assignment_no_alias(this->derived(), other.derived(), internal::assign_op()); ^ /Users/carp/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1/Eigen/src/Core/PlainObjectBase.h:531:7: note: in instantiation of function template specialization 'Eigen::PlainObjectBase >::_set_noalias > > >' requested here _set_noalias(other); ^ /Users/carp/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1/Eigen/src/Core/Matrix.h:379:9: note: in instantiation of function template specialization 'Eigen::PlainObjectBase >::PlainObjectBase > > >' requested here : Base(other.derived()) ^ fph.cpp:9:30: note: in instantiation of function template specialization 'Eigen::Matrix::Matrix > > >' requested here MatrixXd m_inv_transpose = hh.inverse(); ^ /Users/carp/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1/Eigen/src/Core/AssignEvaluator.h:851:8: note: partial specialization matches [with DstXprType = Eigen::Matrix, SrcXprType = Eigen::Inverse > >, Functor = Eigen::internal::assign_op, Weak = void] struct Assignment ^ /Users/carp/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1/Eigen/src/LU/InverseImpl.h:290:8: note: partial specialization matches [with DstXprType = Eigen::Matrix, XprType = Eigen::FullPivHouseholderQR >] struct Assignment, internal::assign_op, Dense2Dense> ^ /Users/carp/cmdstan/stan/lib/stan_math/lib/eigen_3.3.rc1/Eigen/src/QR/FullPivHouseholderQR.h:579:8: note: partial specialization matches [with DstXprType = Eigen::Matrix, MatrixType = Eigen::Matrix, Scalar = double] struct Assignment >, internal::assign_op, Dense2Dense> ^ 1 error generated.
initialisation of iterator with a reference
in C++11: I want to create an iterator from a reference. this is to make a loop starting from a given position rather than from begin(). I tried: typename std::vector<T>::iterator ref2iter(T& x) { return &x ; } ; but was answered: conversion from ‘double*’ to non-scalar type ‘std::vector<double, std::allocator<double> >::iterator {aka __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >}’ requested