C++ no matching function call to transform when using lambda - c++

Okay, very stumped on this one. Works with Visual Studio, but not Code::Blocks (GNU compiler).
transform(m_teams.begin(), m_teams.end(), inserter(teamNames, teamNames.end()),
[](stVecPair team) -> string { return team.first; });
m_teams is a map : typedef map<string, vector<Person*> > stVecMap;
teamNames is a set : typedef set<string> StrSet;
stVecPair is a pair matching m_teams : typedef pair<string, vector<Person*> > stVecPair;
Full Error
error: no matching function for call to 'transform(std::map<std::basic_string<char>,
std::vector<Person*> >::const_iterator, std::map<std::basic_string<char>,
std::vector<Person*> >::const_iterator, std::insert_iterator<std::set<std::basic_string<char> > >,
RaceAnalyzer::teams() const::<lambda(RaceAnalyzer::stVecPair&)>)

As I commented, you've forgotten -std=c++11 option >o<

Related

Eclipse CDT cannot display stl::map information

I had a problem when using Eclipse CDT with detecting stl information. I got in-editor errors like "symbol vector could not be resolved". I have solved this using the solution described here:
https://stackoverflow.com/a/13524483/613173
However, it seems that stl::map still has problems. For example, the line
std::map<int,int> a;
Gets the "invalid template arguments" error. Also,
a.begin();
Gives "method 'begin' could not be resolved" error.
However, with default parameters given explicitly:
std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > > b;
I got none of those errors. This does not happen with other classes such as std::vector whose template also has more than one argument but I get no complaints over
std::vector<int> a;
Another problem regards iterators. Even if the map was defined with all parameters given explicitly, the "first" and "second" fields give an error:
std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator i_b = b.begin();
i_b->first;
This gives "Field 'first' could not be resolved".
Compilation works without problems, obviously, but I still want to be able to use Eclipse's static error detection and auto completion.
Eclipse 4.4.2, CDT 8.6.

map error while coding for ARM9 using ADS 1.2 compiler and ARM11 RVCT2.2

I'm porting my code which written in cpp to support ARM9 using ADS 1.2 compiler,but after porting the below code gives error while compiling for ARM11 using RVCT2.2 compiler, this is the sample code
list<int,allocator<int> > mystack;
map<int*,list<int,allocator<int> >,less<int*>,allocator<pair<int*,list<int,allocator<int> > > > > mymap;
mymap[addr] = mystack;
Error 1:Error: #167:argument of type "std::allocator<std::pair<int *,
std::list<int, std::allocator<int>>>>::const_pointer" is incompatible with
parameter of type "std::allocator<std::pair<int *, std::list<int,
std::allocator<int>>>>::pointer"
Error 2:Error: #434: a reference of type
"__rw::__rw_tree_iter<__rw::__rb_tree<std::map<int *, std::list<int,
std::allocator<int>>, std::less<int *>, std::allocator<std::pair<int *,
std::list<int, std::allocator<int>>>>>::key_type, std::map<int *,
std::list<int, std::allocator<int>>, std::less<int *>,
std::allocator<std::pair<int *, std::list<int,
std::allocator<int>>>>>::value_type, (not const-qualified) cannot be
initialized with a value of type "std::map<int *, std::list<int,
std::allocator<int>>, std::less<int *>, std::allocator<std::pair<int *,
std::list<int, std::allocator<int>>>>>::value_type"
return _C_node->_C_value();
The problem you have is the allocator for std::map needs to be pair of
std::pair<const Key, T>
Right not you have
pair<int*,list<int,allocator<int> > >
Which is not the same as you do not have the Key const qualified. It should be
pair<int* const,list<int,allocator<int> > >
Since you are using the standard allocator there is no reason to specify the allocator. You can just use
list<int> mystack;
map<int*,list<int>> mymap;
mymap[addr] = mystack;
And the list will default to using a std::allocator<int> and the map will default to using std::less<int*> and std::allocator<int * const, std::list<int>>
Also not that std::less<int*> do not compare the values the int* points to but instead it compares the address. If you need the former you need to write your own comparison object to do that.

compile error for boost::date_time::days_until_weekday

I'm currently toying around with boost::date_time. While doing so, I came upon the days_until_weekday (documentation link) function which appears highly useful to me. Unfortunately, I get a compile time error from the following snippet
date f(date d){
return next_weekday(d, boost::date_time::weekdays::Friday);
}
reading
> In file included from
> /usr/include/boost/date_time/gregorian/gregorian_types.hpp:25:0,
> from /usr/include/boost/date_time/posix_time/posix_time_config.hpp:18,
> from /usr/include/boost/date_time/posix_time/posix_time_system.hpp:13,
> from /usr/include/boost/date_time/posix_time/ptime.hpp:12,
> from /usr/include/boost/date_time/posix_time/posix_time.hpp:15,
> from prog.cpp:3: /usr/include/boost/date_time/date_generators.hpp: In instantiation of
> 'typename date_type::duration_type
> boost::date_time::days_until_weekday(const date_type&, const
> weekday_type&) [with date_type = boost::gregorian::date; weekday_type
> = boost::date_time::weekdays; typename date_type::duration_type = boost::gregorian::date_duration]':
> /usr/include/boost/date_time/date_generators.hpp:488:34: required
> from 'date_type boost::date_time::next_weekday(const date_type&, const
> weekday_type&) [with date_type = boost::gregorian::date; weekday_type
> = boost::date_time::weekdays]' prog.cpp:11:67: required from here /usr/include/boost/date_time/date_generators.hpp:452:37: error:
> request for member 'as_number' in 'wd', which is of non-class type
> 'const boost::date_time::weekdays'
> duration_type dd(wd.as_number() - d.day_of_week().as_number());
Go here for a paste of my code.
As the snippet causing the error is so short, I'm really out of ideas to fix this.
By the way, I'm on boost 1.60.0 using clang 3.7.0.
You need to convert the date_time enum to an object that matches the interface expected by the weekday_type passed to the function. Use the greg_weekday function to do this for you, eg:
return next_weekday(d, boost::gregorian::greg_weekday(boost::date_time::Friday));
That compiles for me under VS2015 and boost 1.53.
A link to the documentation for this function:
greg_weekday

boost mpl fold placeholder expression fails to compile

I'm trying to compile the Statemachine example from boost-mpl (located in libs/mpl/examples/fsm/player2.cpp), but it fails with boost version 1.37 and g++ 4.8.2. With boost version 1.56 and the same compiler, the build succeeds. Unfortunately, due to some platform constraints, I cannot switch to version 1.56.
I'm not expecting anyone to look into the above mentioned lengthy example, therefore I identified a minimal code snippet which illustrates the problem:
#include <boost/mpl/fold.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/placeholders.hpp>
namespace mpl = boost::mpl;
using namespace mpl::placeholders;
//Basic queue datatype
template< class CURRENT, class NEXT >
struct queue_element
{
typedef typename CURRENT::mytype mytype;
};
//type to be put at the end of the queue
struct default_queue_element
{
};
template <class TYPE>
struct wrapper{
typedef TYPE mytype;
};
typedef mpl::vector<wrapper<int>, wrapper<char> > myvector;
//the following fold expression should create this type:
typedef queue_element<wrapper<char>, queue_element<wrapper<int>,
default_queue_element> > this_type_should_be_created;
//This typedef fails to compile with boost Version 1.37,
//but works perfectly with version 1.56
typedef typename
mpl::fold<
myvector
,default_queue_element
,queue_element<_2,_1>
>::type
generate_queue;
With boost 1.37, g++ issues the following errors:
foldtest2.cpp: In instantiation of ‘struct queue_element<mpl_::arg<2>, mpl_::arg<1> >’:
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/template_arity.hpp:85:5: required from ‘const int boost::mpl::aux::template_arity_impl<queue_element<mpl_::arg<2>, mpl_::arg<1> >, 1>::value’
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/template_arity.hpp:93:5: required from ‘const int boost::mpl::aux::template_arity<queue_element<mpl_::arg<2>, mpl_::arg<1> > >::value’
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/template_arity.hpp:98:30: required from ‘struct boost::mpl::aux::template_arity<queue_element<mpl_::arg<2>, mpl_::arg<1> > >’
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/apply.hpp:67:8: required from ‘struct boost::mpl::apply2<queue_element<mpl_::arg<2>, mpl_::arg<1> >, default_queue_element, wrapper<int> >’
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp:67:85: required from ‘struct boost::mpl::aux::fold_impl<2, boost::mpl::v_iter<boost::mpl::vector<wrapper<int>, wrapper<char> >, 0l>, boost::mpl::v_iter<boost::mpl::vector<wrapper<int>, wrapper<char> >, 2l>, default_queue_element, queue_element<mpl_::arg<2>, mpl_::arg<1> > >’
../boost_1_37_0/boost/mpl/fold.hpp:39:18: required from ‘struct boost::mpl::fold<boost::mpl::vector<wrapper<int>, wrapper<char> >, default_queue_element, queue_element<mpl_::arg<2>, mpl_::arg<1> > >’
foldtest2.cpp:39:6: required from here
foldtest2.cpp:15:38: error: no type named ‘mytype’ in ‘struct mpl_::arg<2>’
typedef typename CURRENT::mytype mytype;
Is there a work-around to make the code compile with boost 1.37? I have been searching the web for quite some time. If nevertheless the question has already been answered somewhere, I would be grateful if you could point that out.
Looks to be very simply a bug in that ancient(¹) version of boost.
A quick bisection tells me it was fixed in v1.43.0(²). Release notes don't disclose the secret, but git does:
c5621d9 MPL: merge fix for ticket #1992 boost::mpl::zip_view does not support use as a metafunction with ::type
31a2c78 MPL: merge fix for ticket #4061 [MPL] gcc-4.5 compilation problems related to arity_helper
It clearly appears to be the latter (confirmed by compiling against 31a2c78).
So your fix this single line in include/boost/mpl/aux_/template_arity.hpp(³):
sizeof(arity_helper(type_wrapper<F>(),arity_tag<N>())) - 1
should be
sizeof(::boost::mpl::aux::arity_helper(type_wrapper<F>(),arity_tag<N>())) - 1
Of course the proper way to fix this is to use a supported version of boost
¹ (November 3rd, 2008)!!
² (May 6th, 2010)
³ warning: also present in several copies generated in preprocessed versions of the header

Boost ( 1.34) Regex syntax bug

I have read some amount of documentation, and I am more familiar with the current version being shipped with VS2010. But for now I am stuck with ubuntu 8.04, and boost 1.34 and am getting some weird sort of error. Can anybody tell what I am doing wrong. Here is the man page for regex_search boost v1.34
Here is what I am doing in my code :
std::string sLine;
getline(dataFile, sLine);
boost::match_results<std::string::const_iterator> lineSmatch;
boost::match_flag_type regFlags = boost::match_default;
boost::regex finalRegex(linePattern);
boost::regex_search(sLine.begin(), sLine.end(), lineSmatch, finalRegex, regFlags);
Here is the compilation error:
error: no matching function for call to 'regex_search(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >&, boost::regex&, boost::regex_constants::match_flag_type&)'
If you are going to apply regex_search to sLine itself instead of
iterator range, as Howard answered, you can use sLine instead of
begin() and end().
For example:
boost::regex_search(sLine, lineSmatch, finalRegex, regFlags);
If you have to give iterator range to regex_search, since the type
argument for match_results is const_iterator, the first and second
arguments for regex_search need to be const_iterator too.
For example:
std::string::const_iterator b = sLine.begin(), e = sLine.end();
boost::regex_search(b, e, lineSmatch, finalRegex, regFlags);
Hope this helps
Can't help you specifically with ubuntu 8.04, and boost 1.34. However the following compiles for me on libc++ which implements C++11. Perhaps it is close enough to your environment to tell you what is wrong.
#include <regex>
#include <fstream>
int main()
{
std::ifstream dataFile;
std::string sLine, linePattern;
getline(dataFile, sLine);
std::match_results<std::string::const_iterator> lineSmatch;
std::regex_constants::match_flag_type regFlags =
std::regex_constants::match_default;
std::regex finalRegex(linePattern);
std::regex_search(sLine, lineSmatch, finalRegex, regFlags);
}