2

So I was deep in the depths of my code writing an erase method for my container class when I went to call std::vector::erase with a const_iterator and if failed mightily. Just like it did for this person.

Following the links to gnu libstdc++ status shows that this issue has still not been fixed (the original question was early 2013).

So I coded up a horrible hack-around:

#if 1
    // horrible hack for gnu libstd++ deficit 
    // current implementation does not allow erase(const_iterator), so recreate plain iterator 
   off_t::iterator itx= offsets_.begin() + ( apos.iter() - offsets_.begin() ) ;
#else
    // for compliant implementations 
   auto itx= apos.iter() ;
#endif

But I am wondering if there is #define I can use the relates to the version of libstdc++. There are plenty to test for the version of the compiler, but I don't think that gcc versions are going to be a good indicator for when this is fixed, and since clang uses the same library by default I need to catch it either way. I took a look at the output of g++ -E -dM - < /dev/null but the only ones that even mentioned STD didn't seem to promising:

#define __STDC_HOSTED__ 1
#define __STDC_IEC_559__ 1
#define __STDC_ISO_10646__ 201103L
#define __STDC_NO_THREADS__ 1
#define _STDC_PREDEF_H 1
#define __STDC_IEC_559_COMPLEX__ 1
#define __STDC__ 1
Community
  • 1
  • 1
woolstar
  • 5,063
  • 20
  • 31
  • The [libstdc++ website](http://gcc.gnu.org/libstdc++/) says "*libstdc++-v3 is developed and released as part of GCC, separate snapshots are no longer made available.*". So checking GCC versions is probably what you should be doing. – Praetorian Jan 27 '14 at 23:51
  • Ya, that still leaves me on the hook if I'm compiling with `clang`. – woolstar Jan 28 '14 at 05:29

1 Answers1

3

Won't you be on the hook with clang anyway? If it's fixed by the gcc distribution, is it guaranteed to be fixed by clang and visa versa? How about the other compilers?

You can obtain a list of compiler defines

For example

#define __GNUC_PATCHLEVEL__
#define __GNUC__
#define __GNUC_MINOR__ 

or for clang

#define __clang__ 
#define __clang_major__ 
#define __clang_minor__ 
#define __clang_patchlevel__ 

Do you use autotools? If so, then since you're thinking of macro-ing yourself out of this situation anyway, you can create an autotools test to create your own define. The test doesn't need to compile, in fact that typically IS the test.

waTeim
  • 9,095
  • 2
  • 37
  • 40