Boost C++ Libraries: Ticket #11028: Overloading ambiguity between basic_string & insert(0,...) and iterator insert(0,...) https://svn.boost.org/trac10/ticket/11028 <ol><li>Description of the failure </li></ol><p> Let's consider the following 7 line t.cc test: </p> <p> #include &lt;string&gt; </p> <p> #include &lt;iostream&gt; </p> <p> int main() { </p> <blockquote> <p> std::string s; </p> </blockquote> <blockquote> <p> s.insert(0, 1, '1'); </p> </blockquote> <blockquote> <p> std::cout &lt;&lt; s &lt;&lt; std::endl; </p> </blockquote> <p> } Its complation on Solaris 11.2 with Oracle Studio 12.4 C++ compiler using -library=stlport4 option (which tells compiler to use STL Standard library) produces the following error messages </p> <p> "l.cc", line 6: Error: Overloading ambiguity between </p> <p> "std::string::insert(char*, unsigned, char)" and </p> <p> "std::string::insert(unsigned, unsigned, char)". </p> <p> The similar code containing </p> <blockquote> <p> &lt;id&gt;.insert(0,&lt;integer&gt;,'&lt;character&gt;'); </p> </blockquote> <p> exist in the following 7 headers of multiprecision library: </p> <blockquote> <p> multiprecision/tommath.hpp </p> </blockquote> <blockquote> <p> multiprecision/cpp_dec_float.hpp </p> </blockquote> <blockquote> <p> multiprecision/cpp_bin_float/io.hpp </p> </blockquote> <blockquote> <p> multiprecision/cpp_int.hpp </p> </blockquote> <blockquote> <p> multiprecision/number.hpp </p> </blockquote> <blockquote> <p> multiprecision/detail/number_base.hpp </p> </blockquote> <blockquote> <p> multiprecision/detail/float_string_cvt.hpp </p> </blockquote> <p> which is the reason for numerous compilation failures in regression unit tests of multiprecision library when any of 3 Standard librarries (Apache, STL, RW) are used with Studio 12.4 C++ compiler. </p> <ol start="2"><li>Cause of the failure. </li></ol><p> This failure is a direct consequence of STL implementation detail for string iterators. C++ standard requires STL to provide the following string::insert member functions: </p> <blockquote> <p> basic_string&amp; insert(size_type pos, size_type n, charT c); </p> </blockquote> <blockquote> <p> iterator insert(const_iterator p, size_type n, charT c); </p> </blockquote> <p> Unfortunately, iterator for strings in stlport4 is implemented as 'char *' and that causes the following call to match both of these insert functions: </p> <blockquote> <p> insert(0, 1, '1'); </p> </blockquote> <p> That happens because 0 is a valid value both for 'size_type' and 'iterator'. And that naturally leads to the compilation failure shown above. </p> <p> So its not a compiler problem but rather incompatibility between Boost sources and these STLs. </p> <ol start="3"><li>Possible Solution. </li></ol><p> To replace all lines: </p> <p> &lt;id&gt;.insert(0,&lt;integer&gt;,'&lt;character&gt;'); </p> <p> with: </p> <p> &lt;id&gt;.insert(std::string::size_type(0)&lt;integer&gt;,'&lt;character&gt;'); </p> <p> in 7 boost header files listed above. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11028 Trac 1.4.3 John Maddock Sun, 22 Feb 2015 13:25:29 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11028#comment:1 https://svn.boost.org/trac10/ticket/11028#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> Ticket