compile error for boost::date_time::days_until_weekday - c++

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

Related

Seqan mini-bowtie example not compiling

I try to copy the example of mini-bowtie from the Seqan Web site.
Note that the example comes from version 1.4.2, not the current one.
When I compile, I have an error.
The minimal reproducible example is:
#include <seqan/index.h>
#include <seqan/store.h>
using namespace seqan;
int main()
{
typedef Index<StringSet<Dna5String>, FMIndex<> > TIndex;
typedef Iterator<TIndex, TopDown<ParentLinks<> > >::Type TIter;
FragmentStore<> fragStore;
StringSet<Dna5String> text;
TIndex fmIndex(text);
TIter it(fmIndex);
it = TIter(fmIndex); // This does not work
return 0;
}
The compiling error is quite long.
It starts with:
In file included from test.cpp:1:
In file included from /usr/include/seqan/index.h:172:
/usr/include/seqan/index/index_fm_stree.h:469:16: error: no matching constructor for initialization of 'TVertexDescriptor' (aka 'VertexFM<unsigned long, seqan::SimpleType<unsigned char, seqan::Dna5_> >')
return TVertexDescriptor(back(it.history).range, back(it.history).repLen, back(it.history).lastChar);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/seqan/index/index_esa_stree.h:245:27: note: in instantiation of function template specialization 'seqan::nodeUp<seqan::StringSet<seqan::String<seqan::SimpleType<unsigned char, seqan::Dna5_>,
seqan::Alloc<void> >, seqan::Owner<seqan::Tag<seqan::Default_> > >, void, seqan::FMIndexConfig<void, unsigned long, 1, 1>, seqan::Preorder>' requested here
_parentDesc = nodeUp(_origin);
^
/usr/include/seqan/index/index_esa_stree.h:366:29: note: in instantiation of function template specialization 'seqan::Iter<seqan::Index<seqan::StringSet<seqan::String<seqan::SimpleType<unsigned char,
seqan::Dna5_>, seqan::Alloc<void> >, seqan::Owner<seqan::Tag<seqan::Default_> > >, seqan::FMIndex<void, seqan::FMIndexConfig<void, unsigned long, 1, 1> > >, seqan::VSTree<seqan::TopDown<seqan::Preorder> >
>::operator=<seqan::ParentLinks<seqan::Preorder> >' requested here
*(TBase*)(this) = _origin;
^
test.cpp:17:8: note: in instantiation of member function 'seqan::Iter<seqan::Index<seqan::StringSet<seqan::String<seqan::SimpleType<unsigned char, seqan::Dna5_>, seqan::Alloc<void> >,
seqan::Owner<seqan::Tag<seqan::Default_> > >, seqan::FMIndex<void, seqan::FMIndexConfig<void, unsigned long, 1, 1> > >, seqan::VSTree<seqan::TopDown<seqan::ParentLinks<seqan::Preorder> > > >::operator='
requested here
it = TIter(fmIndex);
^
It seems that the API has slightly changed, but I cannot exactly put the finger on it.
I compile with:
clang++ -Wall -Wextra -Weffc++ -O2 -o testSeqan test.cpp -lrt
with clang++ 6.0.0-1ubuntu2 x86_64-pc-linux-gnu, but g++ Ubuntu 7.3.0-16ubuntu3 gives similar (albeit less readable) results, and Seqan version 2.3.2.
What should I change?

Why does std::list<string> work but not std::list<int>

I'm using templates while implementing AVL trees on Ubuntu.
The file will not compile when I write template class AVLTree<std::list<int> >;, it tells me:
undefined reference to `AVLTree < std::__cxx11::list < 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> > > > >::insert(std::__cxx11::basic_string < char, std::char_traits < char>, std::allocator < char> >)'
And I don't get what it doesn't have the reference to.
But it compiles just fine when I write template class AVLTree<std::list<string> >;
I need to let AVLTree store linked lists that store string values.
Why does one compile and the other doesn't? How to solve my problem?
PS: I've included <list>, <string>, and <iostream>, along with my own header file.
Examining the error message closely shows that linker cannot find the AVLTree::insert(string) method.
Based on the sparse information that you posted, my best hypothesis is that you changed the template parameter in the following line from list<string> to list<int>:
template class AVLTree<std::list<string>>;
This line of code explicitly tells the compiler to instantiate a version of the AVLTree template using list<string> as the template parameter. Thus, when you try to compile the code after the change it gives you the error message that it cannot find the AVLTree::insert(string) function because the compiler is now generating the code for list<int> instead.
Your program contains other code that is referencing AVLTree<list<string>>. At a minimum you will have to update that code to use list<int> as well.
Plus, if you simplify the problem down to something you can post the code for on this site, then you will either find the issue during that process or at least have a change of getting a good answer.

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

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

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<

How to deal with way too long STL template error report?

When programming in c++ STL, or intensively using 'templatization', and some compiling error happens, often the error report is really long, and often too much not needed information is given.
I'm talking about gcc, i don't know if with other compilers is different, but some times even for just a typo, it takes a while to catch the error purging the
<ns::type<ns::type<ns::type, ns::type<...><ns::type<...> > > > >
I'm looking for some compiler flag, trick, workaround or methodology ( i currently copy past the error and put on two lines what i have and what compiler use to want and removing variables bookmarks... (kinda sad procedure for a not-so-uncommon ctrl+s non well performed)) that could make this task quicker or just helping me ( even only some IDE error syntax highlight... )
STLFilt: An STL Error Message Decryptor for C++ is a popular tool to filter these verbose error messages and turn them into something more legible.
From their website:
STLFilt was initially conceived as a teaching aid, to allow students
taking C++ and/or STL-specific workshops to make sense of typically
overbloated STL error messages. Today, however, even some C++ experts
have adopted STLFilt for use in everyday development. The results may
not always be perfect, but most of the time the information lost
during Decryption is not critical to the application being debugged.
The rest of the time, Decryption is easy enough to bypass.
The distribution for each platform (compiler/library set) is
self-contained and tuned to the idiosyncrasies of that platform. Each
Perl script performs basic regex substitutions for all the standard
(and extended, if present in the library) STL components, while
certain versions of the script go further with respect to message
ordering, line wrapping, library header error treatment, etc., as I
unilaterally deemed appropriate for that platform.
Here's a demo run that shows how it can be useful:
The source program:
#include <map>
#include <algorithm>
#include <cmath>
const int values[] = { 1,2,3,4,5 };
const int NVALS = sizeof values / sizeof (int);
int main()
{
using namespace std;
typedef map<int, double> valmap;
valmap m;
for (int i = 0; i < NVALS; i++)
m.insert(make_pair(values[i], pow(values[i], .5)));
valmap::iterator it = 100; // error
valmap::iterator it2(100); // error
m.insert(1,2); // error
return 0;
}
First, an unfiltered run using the MinGW gcc 3.2 compiler:
d:\src\cl\demo>c++2 rtmap.cpp
rtmap.cpp: In function `int main()':
rtmap.cpp:19: invalid conversion from `int' to `
std::_Rb_tree_node<std::pair<const int, double> >*'
rtmap.cpp:19: initializing argument 1 of `std::_Rb_tree_iterator<_Val, _Ref,
_Ptr>::_Rb_tree_iterator(std::_Rb_tree_node<_Val>*) [with _Val =
std::pair<const int, double>, _Ref = std::pair<const int, double>&, _Ptr =
std::pair<const int, double>*]'
rtmap.cpp:20: invalid conversion from `int' to `
std::_Rb_tree_node<std::pair<const int, double> >*'
rtmap.cpp:20: initializing argument 1 of `std::_Rb_tree_iterator<_Val, _Ref,
_Ptr>::_Rb_tree_iterator(std::_Rb_tree_node<_Val>*) [with _Val =
std::pair<const int, double>, _Ref = std::pair<const int, double>&, _Ptr =
std::pair<const int, double>*]'
E:/GCC3/include/c++/3.2/bits/stl_tree.h: In member function `void
std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(_II,
_II) [with _InputIterator = int, _Key = int, _Val = std::pair<const int,
double>, _KeyOfValue = std::_Select1st<std::pair<const int, double> >,
_Compare = std::less<int>, _Alloc = std::allocator<std::pair<const int,
double> >]':
E:/GCC3/include/c++/3.2/bits/stl_map.h:272: instantiated from `void std::map<_
Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _Input
Iterator = int, _Key = int, _Tp = double, _Compare = std::less<int>, _Alloc = st
d::allocator<std::pair<const int, double> >]'
rtmap.cpp:21: instantiated from here
E:/GCC3/include/c++/3.2/bits/stl_tree.h:1161: invalid type argument of `unary *
'
And a filtered run using the gcc-specific Proxy c++:
d:\src\cl\demo>c++ rtmap.cpp
*** {BD Software Proxy c++ for gcc v3.01} STL Message Decryption is ON! ***
rtmap.cpp: In function `int main()':
rtmap.cpp:19: invalid conversion from `int' to `iter'
rtmap.cpp:19: initializing argument 1 of `iter(iter)'
rtmap.cpp:20: invalid conversion from `int' to `iter'
rtmap.cpp:20: initializing argument 1 of `iter(iter)'
stl_tree.h: In member function `void map<int,double>::insert_unique(_II, _II)':
[STL Decryptor: Suppressed 1 more STL standard header message]
rtmap.cpp:21: instantiated from here
stl_tree.h:1161: invalid type argument of `unary *'
STL Decryptor reminder:
Use the /hdr:L option to see all suppressed standard lib headers
[Note: demo runs were performed in an 80-column console window with
STLFilt's intelligent line wrapping enabled, and with internal
switches set to produce messages as terse as possible. More detail is
available by tailoring the Decryptor's options.]
The only downside I can see is that it mislabels the C++ Standard Library. :(
Here's a relevant journal article by STLFilt's author.
A few people have made tools to perform this, as there's nothing inbuilt. Tonnes on Google, but the top result returns: http://www.bdsoft.com/tools/stlfilt.html
It should be compatible with visual studio and gcc.
edit::
I need to type less to actually get input in time :)