What do these errors mean? - c++

I'm relatively new to C++, so I kind of glaze over when I see these monstrous template involving errors.
Here's my code:
#include "scene.hpp"
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
// projects a ray from the eyepoint through (x, y) in the image plane
Ray Camera::project_ray(int x, int y){
}
class scene_parser{
public:
class unimplemented_exception {};
class unknown_command_exception {};
class malformed_command_exception {};
scene_parser(Scene &s);
void parse(const std::string &filename);
private:
PixelBufferPTR current_texture;
Colour current_material_colour;
Material current_material;
typedef void (scene_parser::*parsefunc )(std::vector<std::string>);
std::map<std::string, parsefunc> funcMap;
void init_funcMap();
void apply_func(const std::vector<std::string> &line);
// methods which parse the scene file
// they each receive a line of the file, tokenized on whitespace
void camera_from(std::vector<std::string> line);
void camera_target(std::vector<std::string> line);
void camera_forw(std::vector<std::string> line);
void camera_up(std::vector<std::string> line);
void camera_angle(std::vector<std::string> line);
void camera_resolution(std::vector<std::string> line);
void sphere(std::vector<std::string> line);
void tsphere(std::vector<std::string> line);
void texture(std::vector<std::string> line);
void mesh(std::vector<std::string> line) {throw unimplemented_exception();}
void background(std::vector<std::string> line);
void ambient_light(std::vector<std::string> line);
void parallel_light(std::vector<std::string> line);
void point_light(std::vector<std::string> line);
void spot_light(std::vector<std::string> line) {throw unimplemented_exception();}
void material(std::vector<std::string> line);
void render(std::vector<std::string> line);
void trace_depth(std::vector<std::string> line);
};
scene_parser::scene_parser(Scene &s) : current_material_colour(0, 0, 0), current_material(0, 0, 0, 0, 0) {
init_funcMap();
}
void scene_parser::init_funcMap(){
funcMap["camera_from"] = &scene_parser::camera_from;
funcMap["camera_target"] = &scene_parser::camera_target;
funcMap["camera_forw"] = &scene_parser::camera_forw;
funcMap["camera_up"] = &scene_parser::camera_up;
funcMap["camera_angle"] = &scene_parser::camera_angle;
funcMap["camera_resolution"] = &scene_parser::camera_resolution;
funcMap["sphere"] = &scene_parser::sphere;
funcMap["tsphere"] = &scene_parser::tsphere;
funcMap["texture"] = &scene_parser::texture;
funcMap["mesh"] = &scene_parser::mesh;
funcMap["background"] = &scene_parser::background;
funcMap["ambient_light"] = &scene_parser::ambient_light;
funcMap["parallel_light"] = &scene_parser::parallel_light;
funcMap["point_light"] = &scene_parser::point_light;
funcMap["spot_light"] = &scene_parser::spot_light;
funcMap["material"] = &scene_parser::material;
funcMap["render"] = &scene_parser::render;
funcMap["trace_depth"] = &scene_parser::trace_depth;
}
void scene_parser::apply_func(const std::vector<std::string> &line){
if(line.size() != 0){
std::map<std::string, parsefunc>::iterator it = funcMap.find(line[0]);
if(it == funcMap.end()) throw unknown_command_exception();
else{
parsefunc f = it->second;
this->*f(line); //line 86
}
}
}
void scene_parser::parse(const std::string &filename){
std::vector<std::string> lines = tokenize_string(file_to_string(filename), "\n");
std::vector<std::vector<std::string> > tokenized_lines;
tokenized_lines.resize(lines.size());
std::transform(lines.begin(), lines.end(), tokenized_lines.begin(), tokenized_lines.end(), std::bind2nd(std::ptr_fun(tokenize_string), std::string(" "))); //line 97
std::for_each(tokenized_lines.begin(), tokenized_lines.end(), std::mem_fun(&scene_parser::apply_func)); //line 99
}
and this is tokenize_string
std::vector<std::string> tokenize_string(const std::string &s, const std::string &split_chars);
and here are the errors:
Scene.cpp: In member function ‘void scene_parser::apply_func(const std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)’:
Scene.cpp:86: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘f (...)’, e.g. ‘(... ->* f) (...)’
In file included from /usr/include/c++/4.4/bits/stl_function.h:712,
from /usr/include/c++/4.4/memory:66,
from light.hpp:4,
from Scene.hpp:4,
from Scene.cpp:1:
/usr/include/c++/4.4/backward/binders.h: At global scope:
/usr/include/c++/4.4/backward/binders.h: In instantiation of ‘std::binder2nd<std::pointer_to_binary_function<const std::string&, const std::string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >’:
Scene.cpp:97: instantiated from here
/usr/include/c++/4.4/backward/binders.h:152: error: ‘typename _Operation::result_type std::binder2nd<_Operation>::operator()(typename _Operation::first_argument_type&) const [with _Operation = std::pointer_to_binary_function<const std::string&, const std::string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]’ cannot be overloaded
/usr/include/c++/4.4/backward/binders.h:146: error: with ‘typename _Operation::result_type std::binder2nd<_Operation>::operator()(const typename _Operation::first_argument_type&) const [with _Operation = std::pointer_to_binary_function<const std::string&, const std::string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]’
In file included from /usr/include/c++/4.4/algorithm:62,
from Scene.cpp:5:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘_OIter std::transform(_IIter1, _IIter1, _IIter2, _OIter, _BinaryOperation) [with _IIter1 = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _IIter2 = __gnu_cxx::__normal_iterator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*, std::vector<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > >, _OIter = __gnu_cxx::__normal_iterator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*, std::vector<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > >, _BinaryOperation = std::binder2nd<std::pointer_to_binary_function<const std::string&, const std::string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]’:
Scene.cpp:97: instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:4741: error: no match for call to ‘(std::binder2nd<std::pointer_to_binary_function<const std::string&, const std::string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >) (std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)’
/usr/include/c++/4.4/backward/binders.h:146: note: candidates are: typename _Operation::result_type std::binder2nd<_Operation>::operator()(const typename _Operation::first_argument_type&) const [with _Operation = std::pointer_to_binary_function<const std::string&, const std::string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = __gnu_cxx::__normal_iterator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*, std::vector<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > >, _Funct = std::mem_fun1_t<void, scene_parser, const std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&>]’:
Scene.cpp:99: instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:4200: error: no match for call to ‘(std::mem_fun1_t<void, scene_parser, const std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&>) (std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)’
/usr/include/c++/4.4/bits/stl_function.h:604: note: candidates are: _Ret std::mem_fun1_t<_Ret, _Tp, _Arg>::operator()(_Tp*, _Arg) const [with _Ret = void, _Tp = scene_parser, _Arg = const std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&]
It was compiled with gcc 4.4 on Ubuntu 10.10.
I'd be grateful for any insight.

Scene.cpp: In member function ‘void scene_parser::apply_func(const std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)’:
Scene.cpp:86: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘f (...)’, e.g. ‘(... ->* f) (...)’
Note the latter part of the second line. You simply have to use parentheses with pointers-to-member-functions (PTMFs):
void scene_parser::apply_func(const std::vector<std::string> &line) {
if (line.size() != 0) {
std::map<std::string, parsefunc>::iterator it = funcMap.find(line[0]);
if (it == funcMap.end()) throw unknown_command_exception();
else {
parsefunc f = it->second;
(this->*f)(line); // line 86 (fixed)
}
}
}
I'd simply use a "normal" for loop to "fix" the other errors; it's unfortunate that template errors can be so nasty and I hate it too.
std::vector<std::vector<std::string> > tokenized_lines;
tokenized_lines.reserve(lines.size());
// c++0x: for (auto const &x : lines) {
for (std::vector<std::string>::const_iterator x = lines.begin(); x != lines.end(); ++x) {
tokenized_lines.push_back(tokenize_string(*x), " "); // no dereference in 0x
tokenized_lines.back().apply_func();
}

Related

Gtest compiler error when invoking function with rvalue argument

I cant for the love of god understand what this compiler error is trying to tell me:
Reproduced here on godbolt: https://godbolt.org/z/v3M5hEbdv
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <string>
#include <functional>
#include <vector>
class MyService {
public:
virtual ~MyService() = default;
virtual void bar(
std::function<void (std::vector<std::string>&&)> onSuccess
) = 0;
};
class MyServiceMock : public MyService
{
public:
MOCK_METHOD(
void,
bar,
(std::function<void(std::vector<std::string>&&)> onSuccess),
(override)
);
};
[[maybe_unused]]
void foo() {
testing::NiceMock<MyServiceMock> myService;
EXPECT_CALL(myService, bar(testing::_))
.Times(testing::Exactly(1))
.WillOnce(testing::DoAll(
testing::Return(),
testing::InvokeArgument<0>(
std::vector<std::string>({"hello", "world"})
)
));
}
int main() {
return 0;
}
The compiler error :
Output of x86-64 gcc 11.2 (Compiler #1)
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/unique_ptr.h:37,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/memory:76,
from /opt/compiler-explorer/libs/googletest/trunk/googletest/include/gtest/gtest.h:55,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple: In instantiation of 'struct std::tuple_element<0, std::tuple<> >':
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/utility:118:11: required by substitution of 'template<long unsigned int __i, class _Tp> using __tuple_element_t = typename std::tuple_element::type [with long unsigned int __i = 0; _Tp = std::tuple<>]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:1403:5: required by substitution of 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_UTypes ...> >&& std::get(const std::tuple<_UTypes ...>&&) [with long unsigned int __i = 0; _Elements = {}]'
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-more-actions.h:515:22: required by substitution of 'template<class ... Args> decltype (testing::internal::InvokeArgument(get<0>(std::forward_as_tuple((forward<Args>)(testing::internal::InvokeArgumentAction<index, Params ...>::operator()::args)...)), declval<const std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&>())) testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::operator()<Args ...>(Args&& ...) const [with Args = {}]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:2466:26: required by substitution of 'template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&; _Args = {}]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:2477:55: required from 'struct std::__result_of_impl<false, false, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&>'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:2482:12: [ skipping 3 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/std_function.h:344:8: required by substitution of 'template<class _Res, class ... _ArgTypes> template<class _Cond, class _Tp> using _Requires = typename std::enable_if<_Cond::value, _Tp>::type [with _Cond = std::function<void()>::_Callable<testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::__invoke_result<testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&> >; _Tp = void; _Res = void; _ArgTypes = {}]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/std_function.h:413:9: required by substitution of 'template<class _Functor, class, class> std::function<void()>::function(_Functor) [with _Functor = testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >; <template-parameter-1-2> = void; <template-parameter-1-3> = <missing>]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:906:30: required from 'struct std::__is_constructible_impl<std::function<void()>, const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&>'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:911:12: required from 'struct std::is_constructible<std::function<void()>, const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&>'
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h:466:7: required by substitution of 'template<class G, class> testing::Action<void(std::function<void(std::vector<std::__cxx11::basic_string<char> >&&)>)>::Action(G&&) [with G = const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&; <template-parameter-1-2> = <missing>]'
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h:1061:56: required from 'testing::internal::DoAllAction<Actions>::operator testing::Action<R(Args ...)>() const [with R = void; Args = {std::function<void(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&)>}; Actions = {testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >}]'
<source>:33:18: required from here
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:1360:25: error: static assertion failed: tuple index must be in range
1360 | static_assert(__i < tuple_size<tuple<>>::value,
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:1360:25: note: '(0 < ((long unsigned int)std::integral_constant<long unsigned int, 0>::value))' evaluates to false
In file included from /opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock.h:57,
from <source>:2:
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h: In instantiation of 'testing::internal::DoAllAction<Actions>::operator testing::Action<R(Args ...)>() const [with R = void; Args = {std::function<void(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&)>}; Actions = {testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >}]':
<source>:33:18: required from here
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h:1061:56: error: could not convert 'std::get<1, testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >(((const testing::internal::DoAllAction<testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >*)this)->testing::internal::DoAllAction<testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >::actions)' from 'std::__tuple_element_t<1, std::tuple<testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > >' {aka 'const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >'} to 'testing::Action<void(std::function<void(std::vector<std::__cxx11::basic_string<char> >&&)>)>'
1061 | std::get<sizeof...(Actions) - 1>(actions)};
| ^
| |
| std::__tuple_element_t<1, std::tuple<testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > {aka const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >}
ASM generation compiler returned: 1
In file included from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/unique_ptr.h:37,
from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/memory:76,
from /opt/compiler-explorer/libs/googletest/trunk/googletest/include/gtest/gtest.h:55,
from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple: In instantiation of 'struct std::tuple_element<0, std::tuple<> >':
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/utility:118:11: required by substitution of 'template<long unsigned int __i, class _Tp> using __tuple_element_t = typename std::tuple_element::type [with long unsigned int __i = 0; _Tp = std::tuple<>]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:1403:5: required by substitution of 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_UTypes ...> >&& std::get(const std::tuple<_UTypes ...>&&) [with long unsigned int __i = 0; _Elements = {}]'
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-more-actions.h:515:22: required by substitution of 'template<class ... Args> decltype (testing::internal::InvokeArgument(get<0>(std::forward_as_tuple((forward<Args>)(testing::internal::InvokeArgumentAction<index, Params ...>::operator()::args)...)), declval<const std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&>())) testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::operator()<Args ...>(Args&& ...) const [with Args = {}]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:2466:26: required by substitution of 'template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&; _Args = {}]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:2477:55: required from 'struct std::__result_of_impl<false, false, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&>'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:2482:12: [ skipping 3 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/std_function.h:344:8: required by substitution of 'template<class _Res, class ... _ArgTypes> template<class _Cond, class _Tp> using _Requires = typename std::enable_if<_Cond::value, _Tp>::type [with _Cond = std::function<void()>::_Callable<testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::__invoke_result<testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&> >; _Tp = void; _Res = void; _ArgTypes = {}]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/std_function.h:413:9: required by substitution of 'template<class _Functor, class, class> std::function<void()>::function(_Functor) [with _Functor = testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >; <template-parameter-1-2> = void; <template-parameter-1-3> = <missing>]'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:906:30: required from 'struct std::__is_constructible_impl<std::function<void()>, const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&>'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/type_traits:911:12: required from 'struct std::is_constructible<std::function<void()>, const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&>'
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h:466:7: required by substitution of 'template<class G, class> testing::Action<void(std::function<void(std::vector<std::__cxx11::basic_string<char> >&&)>)>::Action(G&&) [with G = const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&; <template-parameter-1-2> = <missing>]'
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h:1061:56: required from 'testing::internal::DoAllAction<Actions>::operator testing::Action<R(Args ...)>() const [with R = void; Args = {std::function<void(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&)>}; Actions = {testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >}]'
<source>:33:18: required from here
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:1360:25: error: static assertion failed: tuple index must be in range
1360 | static_assert(__i < tuple_size<tuple<>>::value,
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:1360:25: note: '(0 < ((long unsigned int)std::integral_constant<long unsigned int, 0>::value))' evaluates to false
In file included from /opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock.h:57,
from <source>:2:
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h: In instantiation of 'testing::internal::DoAllAction<Actions>::operator testing::Action<R(Args ...)>() const [with R = void; Args = {std::function<void(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&)>}; Actions = {testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >}]':
<source>:33:18: required from here
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h:1061:56: error: could not convert 'std::get<1, testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >(((const testing::internal::DoAllAction<testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >*)this)->testing::internal::DoAllAction<testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >::actions)' from 'std::__tuple_element_t<1, std::tuple<testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > >' {aka 'const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >'} to 'testing::Action<void(std::function<void(std::vector<std::__cxx11::basic_string<char> >&&)>)>'
1061 | std::get<sizeof...(Actions) - 1>(actions)};
| ^
| |
| std::__tuple_element_t<1, std::tuple<testing::PolymorphicAction<testing::internal::ReturnVoidAction>, testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > {aka const testing::internal::InvokeArgumentAction<0, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >}
Execution build compiler returned: 1
If I remove the &&and change the argument to the function from a rvalue reference into a copy, it compiles fine. What could be happening here?
It seems it is unable to work with r-value references. The workaround:
EXPECT_CALL(myService, bar(testing::_)).WillOnce(
testing::WithArg<0>(
[] (std::function<void (std::vector<std::string>&&)> f) {
f({"hello", "world"});
}
)
Related issue has been closed for some reasons Add support for move only parameters in mocked methods.

Error in a function used to find the position of an element in a vector of string (c++)

I have the following function that works fine that I use to find the position of a string in a string vector:
int FindIndexString(vector <string> *Names, string *name)
{
auto it = find(Names->begin(), Names->end(), name->c_str());
if (it == Names->end())
{
error("FindIndexString: %s not found",name->c_str());
}else{
auto index = distance(Names->begin(), it);
return((int)index);
}
}
I need to use this function in a R program that complains about the "auto" specifier and I cannot compile with C++11.
I changed the function to
int FindIndexString(vector <string> *Names, string *name)
{
vector<string>::iterator it;
it = find(Names->begin(), Names->end(), name->c_str());
int pos = (int)distance(Names->begin(), it);
if(it==Names->end())
{
error("FindIndexString: %s not found",name->c_str());;
}else{
return(pos);
}
}
but it doesn't work and I get the following error
In function 'int FindIndexString(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*, std::string*)':
F_Utils.cpp:92: error: no matching function for call to 'find(__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, const char*)'
Any help?
You need to #include <algorithm> for std::find

Is there any way to insert a unique_ptr into a map in C++0x/gcc 4.4.7)?

I can't figure out how to do it; it's driving me nuts.
#include <iostream>
#include <memory>
#include <map>
int main()
{
std::map<std::string, std::unique_ptr<std::string>> map;
std::unique_ptr<std::string> bar(new std::string("bar"));
map["foo"] = std::move(bar);
std::cout << "foo: " << *(map["foo"]) << std::endl;
}
This compiles just fine on gcc v4.9.2:
$ g++ -std=c++0x test.cc -o test
Unfortunately, all I have available to me is gcc v4.4.7, which produces a hideous error message that I'll stick at the bottom.
I can push_back unique_ptrs into vectors just fine; I don't understand why there's an issue with map.
I've also tried using insert:
int main()
{
std::map<std::string, std::unique_ptr<std::string>> map;
std::unique_ptr<std::string> bar(new std::string("bar"));
auto pair = std::make_pair("foo", std::move(bar));
map.insert(std::move(pair));
std::cout << "foo: " << *(map["foo"]) << std::endl;
}
I can make the pair just fine, but when I try to move it into insert I get the error. It appears that it's trying to call the copy constructor for some reason, but I don't understand why, since I'm moveing it.
emplace has the same result:
int main()
{
std::map<std::string, std::unique_ptr<std::string>> map;
std::unique_ptr<std::string> bar(new std::string("bar"));
auto pair = std::make_pair("foo", std::move(bar));
map.emplace(std::move(pair));
std::cout << "foo: " << *(map["foo"]) << std::endl;
}
Both of these compile fine in g++ v4.9.2, but not in v4.4.7.
Anyone have any ideas on an alternative way to do this (in v4.4.7)?
Full error message output (from the first example):
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algobase.h:66,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/char_traits.h:41,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios:41,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:40,
from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream:40,
from test.cc:1:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/unique_ptr.h: In copy constructor 'std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::pair(const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)':
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h:68: instantiated from 'std::_Rb_tree_node<_Val>::_Rb_tree_node(_Args&& ...) [with _Args = const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&, _Val = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ext/new_allocator.h:111: instantiated from 'void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, _Args&& ...) [with _Args = const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&, _Tp = std::_Rb_tree_node<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_tree.h:394: instantiated from 'std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(_Args&& ...) [with _Args = const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&, _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Val = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _KeyOfValue = std::_Select1st<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_tree.h:881: instantiated from 'std::_Rb_tree_iterator<_Val> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_(const std::_Rb_tree_node_base*, const std::_Rb_tree_node_base*, const _Val&) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Val = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _KeyOfValue = std::_Select1st<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_tree.h:1215: instantiated from 'std::_Rb_tree_iterator<_Val> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique_(std::_Rb_tree_const_iterator<_Val>, const _Val&) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Val = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _KeyOfValue = std::_Select1st<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:540: instantiated from 'typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::insert(typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator, const std::pair<const _Key, _Tp>&) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:450: instantiated from '_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >]'
test.cc:9: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/unique_ptr.h:214: error: deleted function 'std::unique_ptr<_Tp, _Tp_Deleter>::unique_ptr(const std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp_Deleter = std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h:68: error: used here
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/map:60,
from test.cc:3:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_tree.h: In constructor 'std::_Rb_tree_node<_Val>::_Rb_tree_node(_Args&& ...) [with _Args = const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&, _Val = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]':
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_tree.h:136: note: synthesized method 'std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::pair(const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::default_delete<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)' first required here
GCC 4.4.7 does not provide full support for C++ 11 features, so it is unrealistic to expect all C++ 11 features to work properly. In this particular case, the compiler is not generating move assignment and move copy methods for you. So, when std::map attempts assignment or copy, it uses the regular default ones, which are deleted for unique_ptr.
If you just need a smart pointer, you can use shared_ptr instead.
std::map<std::string, std::shared_ptr<std::string>> map;
std::shared_ptr<std::string> bar = std::make_shared<std::string>("bar");
map["foo"] = bar;
I have looked into the issue. STL implementation for map correctly has a move constructor defined in it:
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename... _Args>
_Rb_tree_node(_Args&&... __args)
: _Rb_tree_node_base(),
_M_value_field(std::forward<_Args>(__args)...) { }
#endif
};
Moreover, this is called, as stated in the error output. std::pair has move constructor defined as well, but this one is not called.
I believe, std::forward and deduced type of Args is at fault:
usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_tree.h:
In constructor ‘std::_Rb_tree_node<_Val>::_Rb_tree_node(_Args&& ...)
[with _Args = const std::pair<..., std::unique_ptr<...> >&,
As you see, type of _Args is a const reference, which is forwarded by forward, and regular pair constructor is called.
I assume, one might fiddle with stl_tree.h to fix it - for example, by removing std::forward and just casting the arg to rvalue reference. This would not be correct, of course, but might work for specific case.

C++ Deep Copying a pointer to a map with pointer values

I am having a bit of trouble deep copying a pointer to a map of pointer values.
std::map<string, TH1D*>* m_hist_split;
My current method:
I am using a class template that copies the map pair and initializes the value of the pair on the heap. the template then returns a map::type_value
#ifndef DEEPCOPY_H
#define DEEPCOPY_H
#include <map>
#include <algorithm>
namespace DeepCopy{
template<class A, class B>
struct MapPointerValue{
typedef typename std::map< A, B* >::value_type map_t;
map_t operator() (map_t p){
return std::make_pair(p.first, new B(*p.second) );
}
};
...
...
}
#endif
Inside my copy constructor I then attempt to deep copy my pointer to a map of pointer values.
Cutflow::Cutflow(const Cutflow& cpy){
m_hist_split = new map<string, TH1D*>;
transform(cpy.m_hist_split->begin(),cpy.m_hist_split->end(), inserter(m_hist_split, m_hist_split->begin()), DeepCopy::MapPointerValue<string, TH1D>() );
...
...
}
When compiling I then get an ugly error :-( :
Compiling src/Cutflow.cxx to obj/Cutflow.o
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h: In instantiation of 'std::insert_iterator<std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*>':
src/Cutflow.cxx:42: instantiated from here
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:562: error: 'std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:572: error: 'std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:599: error: 'std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:608: error: 'std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h: In function 'std::insert_iterator<_Container> std::inserter(_Container&, _Iterator) [with _Container = std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*, _Iterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> >]':
src/Cutflow.cxx:42: instantiated from here
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:648: error: 'std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*' is not a class, struct, or union type
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_algo.h: In function '_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation) [with _IIter = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> >, _OIter = std::insert_iterator<std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*>, _UnaryOperation = DeepCopy::MapPointerValue<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D>]':
src/Cutflow.cxx:42: instantiated from here
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_algo.h:4281: error: no match for 'operator=' in '__result.std::insert_iterator<_Container>::operator* [with _Container = std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*]() = DeepCopy::MapPointerValue<A, B>::operator()(typename std::map<A, B*, std::less<_Key>, std::allocator<std::pair<const A, B*> > >::value_type) [with A = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, B = TH1D](std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*>(((const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*>&)((const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*>*)__first.std::_Rb_tree_iterator<_Tp>::operator* [with _Tp = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*>]()))))'
x86_64-slc5-gcc34-opt/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.3.2/../../../../include/c++/4.3.2/bits/stl_iterator.h:559: note: candidates are: std::insert_iterator<std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*>& std::insert_iterator<std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*>::operator=(const std::insert_iterator<std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, TH1D*> > >*>&)
Any ideas what I am doing wrong.
Also,
is what I am doing correct?
:-D
In the following line
transform(cpy.m_hist_split->begin(),cpy.m_hist_split->end(), inserter(m_hist_split, m_hist_split->begin()), DeepCopy::MapPointerValue<string, TH1D>() );
you have mistakenly called the inserter function with a pointer to a map as the first parameter instead of a reference.
For completeness, inserter is defined in §24.5.2.6.5 like this:
template <class Container>
insert_iterator<Container> inserter(Container& x, typename Container::iterator i);
Returns: insert_iterator(x, i)
In this case, a simple typo caused a big headache.

trouble compiling a program using boost regex library

I tried to compile a boost program which was using boost regex library on my linux box. it has all the required headers and libraries. The program refuses to compile throwing a huge dump of template output.
I am using the following command to compile the program.
pls advise on how to fix the below.
g++ regex.cc -I/usr/local/include/boost/ -L/usr/local/lib -lboost_regex -o regex
here is the output of the compiler.
ravit#ravit-laptop:~$ g++ regex.cc -I/usr/local/include/boost/ -L/usr/local/lib -lboost_regex -o regex
In file included from /usr/local/include/boost/regex/v4/perl_matcher.hpp:582,
from /usr/local/include/boost/regex/v4/regex.hpp:88,
from /usr/local/include/boost/regex.hpp:31,
from regex.cc:19:
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp: In member function ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’:
/usr/local/include/boost/regex/v4/perl_matcher_non_recursive.hpp:180: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_all_states() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:323: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_prefix() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:207: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_imp() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:180: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/regex_match.hpp:50: instantiated from ‘bool boost::regex_match(BidiIterator, BidiIterator, boost::match_results<Iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type) [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/regex_match.hpp:82: instantiated from ‘bool boost::regex_match(const std::basic_string<charT, ST, SA>&, boost::match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type) [with ST = std::char_traits<char>, SA = std::allocator<char>, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
regex.cc:30: instantiated from here
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:768: error: request for member ‘back’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:768: error: request for member ‘empty’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:778: error: request for member ‘back’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:778: error: request for member ‘empty’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
here is the piece of code taken from the same boost regex documentation
#include <boost/regex.hpp>
#include <iostream>
void
print_captures(const std::string& regx,
const std::string& text)
{
boost::regex e(regx);
boost::smatch what;
std::cout << "Expression: \"" << regx << "\"\n";
std::cout << "Text: \"" << text << "\"\n";
if(boost::regex_match(text, what, e, boost::match_extra))
{
unsigned i, j;
std::cout << "** Match found **\n Sub-Expressions:\n";
for(i = 0; i < what.size(); ++i)
std::cout << " $" << i << " = \"" << what[i] << "\"\n";
std::cout << " Captures:\n";
for(i = 0; i < what.size(); ++i)
{
std::cout << " $" << i << " = {";
for(j = 0; j < what.captures(i).size(); ++j)
{
if(j)
std::cout << ", ";
else
std::cout << " ";
std::cout << "\"" << what.captures(i)[j] << "\"";
}
std::cout << " }\n";
}
}
else
std::cout << "** No Match found **\n";
}
int main(int , char* [])
{
print_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee");
print_captures("a(b+|((c)*))+d", "abd");
print_captures("(.*)bar|(.*)bah", "abcbar");
print_captures("(.*)bar|(.*)bah", "abcbah");
print_captures("^(?:(\\w+)|(?>\\W+))*$", "now is the time for all good men to come to the aid of the party");
print_captures("^(?>(\\w+)\\W*)*$", "now is the time for all good men to come to the aid of the party");
print_captures("^(\\w+)\\W+(?>(\\w+)\\W+)*(\\w+)$", "now is the time for all good men to come to the aid of the party");
print_captures("^(\\w+)\\W+(?>(\\w+)\\W+(?:(\\w+)\\W+){0,2})*(\\w+)$", "now is the time for all good men to come to the aid of the party");
return 0;
}
Go to the regex.cc file, line 30 (regex.cc:30: instantiated from here) and STARE at it (cross-checking with examples from documentation that DO work) until it becomes clear what you have done wrong. It seems that you're calling back() and empty() on something that does not support these operations. Given [50] at the end of those error messages [which also say non-class type], you've probably forgotten to index an array. (i.e., you have written array.empty() instead of array[i].empty()).
error: request for member ‘.....’ in '......’ is often caused by either using . when you should use -> or adding () at declaration when you shouldn't, for example:
TheClass myTheClass();
instead of
TheClass myTheClass;