简体   繁体   中英

replace_first_copy, so many warnings and errors

I'm trying to use boost 1.61 to replace an occurence of a string:

std::string path = boost::algorithm::replace_first_copy(pathVariable, "%name%", processName);  

The definition of pathVariable:

const char* const pathVariable = "/CalibrationConfig/Processes/ProcessDefinition[@name='%name%']/Variables/Variable";

The prototype of processName which is passed to the function as a parameter:

const std::string& processName

When trying to compile using MSVC2013 I get:

1>------ Build started: Project: something, Configuration: Debug Win32 ------
1>  processfileparser.cpp
1>c:\boost\boost_1_61_0\boost\range\begin.hpp(47): error C2228: left of '.begin' must have class/struct/union
1>          type is 'const char *const '
1>          c:\boost\boost_1_61_0\boost\range\begin.hpp(111) : see reference to function template instantiation 'const char *boost::range_detail::range_begin<const T>(C &)' being compiled
1>          with
1>          [
1>              T=const char *
1>  ,            C=const char *
1>          ]
1>          c:\boost\boost_1_61_0\boost\algorithm\string\find_format.hpp(113) : see reference to function template instantiation 'const char *boost::range_adl_barrier::begin<SequenceT>(const T &)' being compiled
1>          with
1>          [
1>              SequenceT=const char *
1>  ,            T=const char *
1>          ]
1>          c:\boost\boost_1_61_0\boost\algorithm\string\replace.hpp(161) : see reference to function template instantiation 'SequenceT boost::algorithm::find_format_copy<SequenceT,boost::algorithm::detail::first_finderF<T *,boost::algorithm::is_equal>,boost::algorithm::detail::const_formatF<boost::iterator_range<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>>>(const SequenceT &,FinderT,FormatterT)' being compiled
1>          with
1>          [
1>              SequenceT=const char *
1>  ,            T=const char
1>  ,            FinderT=boost::algorithm::detail::first_finderF<const char *,boost::algorithm::is_equal>
1>  ,            FormatterT=boost::algorithm::detail::const_formatF<boost::iterator_range<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>>
1>          ]
1>          processfileparser.cpp(466) : see reference to function template instantiation 'SequenceT boost::algorithm::replace_first_copy<const char*,const char[7],std::string>(const SequenceT &,Range1T (&),const Range2T &)' being compiled
1>          with
1>          [
1>              SequenceT=const char *
1>  ,            Range1T=const char [7]
1>  ,            Range2T=std::string
1>          ]
1>c:\boost\boost_1_61_0\boost\range\end.hpp(48): error C2228: left of '.end' must have class/struct/union
1>          type is 'const char *const '
1>          c:\boost\boost_1_61_0\boost\range\end.hpp(105) : see reference to function template instantiation 'const char *boost::range_detail::range_end<const T>(C &)' being compiled
1>          with
1>          [
1>              T=const char *
1>  ,            C=const char *
1>          ]
1>          c:\boost\boost_1_61_0\boost\algorithm\string\find_format.hpp(113) : see reference to function template instantiation 'const char *boost::range_adl_barrier::end<SequenceT>(const T &)' being compiled
1>          with
1>          [
1>              SequenceT=const char *
1>  ,            T=const char *
1>          ]
1>c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format_store.hpp(77): error C2039: 'type' : is not a member of 'boost::range_const_iterator<InputT,void>'
1>          with
1>          [
1>              InputT=const char *
1>          ]
1>          c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format.hpp(139) : see reference to function template instantiation 'bool boost::algorithm::detail::check_find_result<const InputT,const FindResultT>(InputT &,FindResultT &)' being compiled
1>          with
1>          [
1>              InputT=const char *
1>  ,            FindResultT=boost::iterator_range<const char *>
1>          ]
1>          c:\boost\boost_1_61_0\boost\algorithm\string\find_format.hpp(113) : see reference to function template instantiation 'InputT boost::algorithm::detail::find_format_copy_impl<SequenceT,FormatterT,boost::iterator_range<const char *>>(const InputT &,FormatterT,const FindResultT &)' being compiled
1>          with
1>          [
1>              InputT=const char *
1>  ,            SequenceT=const char *
1>  ,            FormatterT=boost::algorithm::detail::const_formatF<boost::iterator_range<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>>
1>  ,            FindResultT=boost::iterator_range<const char *>
1>          ]
1>c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format_store.hpp(78): error C3203: 'type' : unspecialized class template can't be used as a template argument for template parameter 'IteratorT', expected a real type
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2825: '_Iter': must be a class or namespace when followed by '::'
1>          c:\boost\boost_1_61_0\boost\iterator\iterator_categories.hpp(119) : see reference to class template instantiation 'std::iterator_traits<Iterator>' being compiled
1>          with
1>          [
1>              Iterator=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\range\iterator_range_core.hpp(156) : see reference to class template instantiation 'boost::iterators::iterator_traversal<IteratorT>' being compiled
1>          with
1>          [
1>              IteratorT=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\range\iterator_range_core.hpp(436) : see reference to class template instantiation 'boost::iterator_range_detail::pure_iterator_traversal<IteratorT>' being compiled
1>          with
1>          [
1>              IteratorT=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format_store.hpp(78) : see reference to class template instantiation 'boost::iterator_range<int>' being compiled
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2039: 'iterator_category' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2146: syntax error : missing ';' before identifier 'iterator_category'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2602: 'std::iterator_traits<Iterator>::iterator_category' is not a member of a base class of 'std::iterator_traits<Iterator>'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371) : see declaration of 'std::iterator_traits<Iterator>::iterator_category'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(371): error C2868: 'std::iterator_traits<Iterator>::iterator_category' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(372): error C2825: '_Iter': must be a class or namespace when followed by '::'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(372): error C2039: 'value_type' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(372): error C2146: syntax error : missing ';' before identifier 'value_type'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(372): error C2602: 'std::iterator_traits<Iterator>::value_type' is not a member of a base class of 'std::iterator_traits<Iterator>'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(372) : see declaration of 'std::iterator_traits<Iterator>::value_type'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(372): error C2868: 'std::iterator_traits<Iterator>::value_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(373): error C2825: '_Iter': must be a class or namespace when followed by '::'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(373): error C2039: 'difference_type' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(373): error C2146: syntax error : missing ';' before identifier 'difference_type'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(373): error C2602: 'std::iterator_traits<Iterator>::difference_type' is not a member of a base class of 'std::iterator_traits<Iterator>'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(373) : see declaration of 'std::iterator_traits<Iterator>::difference_type'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(373): error C2868: 'std::iterator_traits<Iterator>::difference_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(375): error C2825: '_Iter': must be a class or namespace when followed by '::'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(375): error C2039: 'pointer' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(375): error C2146: syntax error : missing ';' before identifier 'pointer'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(375): error C2602: 'std::iterator_traits<Iterator>::pointer' is not a member of a base class of 'std::iterator_traits<Iterator>'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(375) : see declaration of 'std::iterator_traits<Iterator>::pointer'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(375): error C2868: 'std::iterator_traits<Iterator>::pointer' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(376): error C2825: '_Iter': must be a class or namespace when followed by '::'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(376): error C2039: 'reference' : is not a member of '`global namespace''
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(376): error C2146: syntax error : missing ';' before identifier 'reference'
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(376): error C2602: 'std::iterator_traits<Iterator>::reference' is not a member of a base class of 'std::iterator_traits<Iterator>'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(376) : see declaration of 'std::iterator_traits<Iterator>::reference'
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(376): error C2868: 'std::iterator_traits<Iterator>::reference' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              Iterator=int
1>          ]
1>c:\boost\boost_1_61_0\boost\mpl\eval_if.hpp(41): error C2516: 'boost::mpl::if_<C,F1,F2>::type' : is not a legal base class
1>          with
1>          [
1>              C=boost::is_convertible<int,std::output_iterator_tag>
1>  ,            F1=boost::mpl::identity<boost::iterators::incrementable_traversal_tag>
1>  ,            F2=void
1>          ]
1>          c:\boost\boost_1_61_0\boost\mpl\if.hpp(70) : see declaration of 'boost::mpl::if_<C,F1,F2>::type'
1>          with
1>          [
1>              C=boost::is_convertible<int,std::output_iterator_tag>
1>  ,            F1=boost::mpl::identity<boost::iterators::incrementable_traversal_tag>
1>  ,            F2=void
1>          ]
1>          c:\boost\boost_1_61_0\boost\mpl\eval_if.hpp(41) : see reference to class template instantiation 'boost::mpl::eval_if<boost::is_convertible<Cat,std::output_iterator_tag>,boost::mpl::identity<boost::iterators::incrementable_traversal_tag>,void>' being compiled
1>          with
1>          [
1>              Cat=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\mpl\eval_if.hpp(41) : see reference to class template instantiation 'boost::mpl::eval_if<boost::is_convertible<Cat,std::input_iterator_tag>,boost::mpl::identity<boost::iterators::single_pass_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::output_iterator_tag>,boost::mpl::identity<boost::iterators::incrementable_traversal_tag>,void>>' being compiled
1>          with
1>          [
1>              Cat=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\mpl\eval_if.hpp(41) : see reference to class template instantiation 'boost::mpl::eval_if<boost::is_convertible<Cat,std::forward_iterator_tag>,boost::mpl::identity<boost::iterators::forward_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::input_iterator_tag>,boost::mpl::identity<boost::iterators::single_pass_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::output_iterator_tag>,boost::mpl::identity<boost::iterators::incrementable_traversal_tag>,void>>>' being compiled
1>          with
1>          [
1>              Cat=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\mpl\eval_if.hpp(41) : see reference to class template instantiation 'boost::mpl::eval_if<boost::is_convertible<Cat,std::bidirectional_iterator_tag>,boost::mpl::identity<boost::iterators::bidirectional_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::forward_iterator_tag>,boost::mpl::identity<boost::iterators::forward_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::input_iterator_tag>,boost::mpl::identity<boost::iterators::single_pass_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::output_iterator_tag>,boost::mpl::identity<boost::iterators::incrementable_traversal_tag>,void>>>>' being compiled
1>          with
1>          [
1>              Cat=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\iterator\iterator_categories.hpp(99) : see reference to class template instantiation 'boost::mpl::eval_if<boost::is_convertible<Cat,std::random_access_iterator_tag>,boost::mpl::identity<boost::iterators::random_access_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::bidirectional_iterator_tag>,boost::mpl::identity<boost::iterators::bidirectional_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::forward_iterator_tag>,boost::mpl::identity<boost::iterators::forward_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::input_iterator_tag>,boost::mpl::identity<boost::iterators::single_pass_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<Cat,std::output_iterator_tag>,boost::mpl::identity<boost::iterators::incrementable_traversal_tag>,void>>>>>' being compiled
1>          with
1>          [
1>              Cat=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\mpl\eval_if.hpp(41) : see reference to class template instantiation 'boost::iterators::detail::old_category_to_traversal<Cat>' being compiled
1>          with
1>          [
1>              Cat=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\iterator\iterator_categories.hpp(113) : see reference to class template instantiation 'boost::mpl::eval_if<boost::is_convertible<Cat,boost::iterators::incrementable_traversal_tag>,boost::mpl::identity<Cat>,boost::iterators::detail::old_category_to_traversal<Cat>>' being compiled
1>          with
1>          [
1>              Cat=int
1>          ]
1>          c:\boost\boost_1_61_0\boost\iterator\iterator_categories.hpp(121) : see reference to class template instantiation 'boost::iterators::iterator_category_to_traversal<int>' being compiled
1>c:\boost\boost_1_61_0\boost\range\iterator_range_core.hpp(156): error C2039: 'type' : is not a member of 'boost::iterators::iterator_traversal<IteratorT>'
1>          with
1>          [
1>              IteratorT=int
1>          ]
1>c:\boost\boost_1_61_0\boost\range\iterator_range_core.hpp(158): error C2955: 'boost::type' : use of class template requires template argument list
1>          c:\boost\boost_1_61_0\boost\type.hpp(14) : see declaration of 'boost::type'
1>c:\boost\boost_1_61_0\boost\range\iterator_range_core.hpp(163): error C2975: 'S' : invalid template argument for 'boost::iterator_range_detail::pure_iterator_traversal_impl', expected compile-time constant expression
1>          c:\boost\boost_1_61_0\boost\range\iterator_range_core.hpp(134) : see declaration of 'S'
1>c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format_store.hpp(78): error C2664: 'boost::iterator_range<int>::iterator_range(const boost::iterator_range<int> &)' : cannot convert argument 1 from 'const boost::iterator_range<const char *>' to 'const boost::iterator_range<int> &'
1>          Reason: cannot convert from 'const boost::iterator_range<const char *>' to 'const boost::iterator_range<int>'
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format.hpp(121): error C2780: 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,const InsertT &)' : expects 3 arguments - 4 provided
1>          c:\boost\boost_1_61_0\boost\algorithm\string\detail\sequence.hpp(39) : see declaration of 'boost::algorithm::detail::insert'
1>          c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format.hpp(144) : see reference to function template instantiation 'InputT boost::algorithm::detail::find_format_copy_impl2<InputT,FormatterT,FindResultT,boost::iterator_range<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>>(const InputT &,FormatterT,const FindResultT &,const FormatResultT &)' being compiled
1>          with
1>          [
1>              InputT=const char *
1>  ,            FormatterT=boost::algorithm::detail::const_formatF<boost::iterator_range<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>>
1>  ,            FindResultT=boost::iterator_range<const char *>
1>  ,            FormatResultT=boost::iterator_range<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>
1>          ]
1>c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format.hpp(121): error C2893: Failed to specialize function template 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,ForwardIteratorT,ForwardIteratorT)'
1>          With the following template arguments:
1>          'InputT=const char *'
1>          'ForwardIteratorT=const char *'
1>c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format.hpp(123): error C2893: Failed to specialize function template 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,const InsertT &)'
1>          With the following template arguments:
1>          'InputT=const char *'
1>          'InsertT=boost::iterator_range<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>'
1>c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format.hpp(123): error C2780: 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,ForwardIteratorT,ForwardIteratorT)' : expects 4 arguments - 3 provided
1>          c:\boost\boost_1_61_0\boost\algorithm\string\detail\sequence.hpp(29) : see declaration of 'boost::algorithm::detail::insert'
1>c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format.hpp(125): error C2780: 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,const InsertT &)' : expects 3 arguments - 4 provided
1>          c:\boost\boost_1_61_0\boost\algorithm\string\detail\sequence.hpp(39) : see declaration of 'boost::algorithm::detail::insert'
1>c:\boost\boost_1_61_0\boost\algorithm\string\detail\find_format.hpp(125): error C2893: Failed to specialize function template 'void boost::algorithm::detail::insert(InputT &,InputT::iterator,ForwardIteratorT,ForwardIteratorT)'
1>          With the following template arguments:
1>          'InputT=const char *'
1>          'ForwardIteratorT=const char *'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Only one of these errors relates to the line I posted:

1>          processfileparser.cpp(466) : see reference to function template instantiation 'SequenceT boost::algorithm::replace_first_copy<const char*,const char[7],std::string>(const SequenceT &,Range1T (&),const Range2T &)' being compiled

The rest are internal to boost.

When called with 3 arguments , the first must be a sequence , which a plain pointer isn't.

You can create a std::string from you literal though:

std::string path = boost::algorithm::replace_first_copy(std::string(pathVariable), "%name%", processName); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM