如何测试libstdc ++的版本 [英] How do I test for a version of the libstdc++

查看:2140
本文介绍了如何测试libstdc ++的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,当我去调用 std :: vector :: erase 时,我深深地在代码中为我的容器类写了一个擦除方法。 c $ c> const_iterator ,如果失败强大。就像这个人一样。



点击 gnu libstdc ++状态的链接后(原来的问题是2013年初)。



所以我编写了一个可怕的黑客:



#if 1
//可怕的hack for gnu libstd ++ deficit
//当前实现不允许擦除(const_iterator),所以重新创建plain iterator
off_t :: iterator itx = offsets_.begin()+('if() - offsets_.begin());
#else
//用于兼容实现
auto itx =';
#endif

但我想知道是否有 #define 我可以使用与 libstdc ++ 的版本相关。有很多的测试版本的编译器,但我不认为 gcc 版本将是一个很好的指示器,当这是固定的,因为 clang 默认使用同一个库,我需要捕获它。我看一下输出 g ++ -E -dM - < / dev / null 但是只有那些甚至提到 STD 似乎没有前途:

  #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


解决方案

你会不会with ang吗?如果它是由gcc分配固定的,是否保证被clang修复,反之亦然?



您可以获取编译器定义



例如

  #define __GNUC_PATCHLEVEL__ 
#define __GNUC__
#define __GNUC_MINOR__

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

您使用 autotools ?如果是这样,那么由于你正在考虑自己处理这种情况,你可以创建一个autotools测试来创建自己的定义。测试不需要编译,事实上通常是测试。


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

解决方案

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.

这篇关于如何测试libstdc ++的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆