Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

icpc-16.0 Update4 does not know std::rbegin() and std::rend()

Toshio_U_1
Beginner
734 Views

Hi, the code below can be compiled fine with g++-5.4.0 under Ubuntu-16.04, but not with icpc-16.0 Update4 even if -std=c++14 specified.

% icpc -V

Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.4.258 Build 20160811

Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

 

% icpc -std=c++14 -O3   -c -o main.o main.cc
main.cc(9): error: namespace "std" has no member "rbegin"
      for (auto iter = std::rbegin(a); iter != std::rend(a); ++iter)
                            ^

main.cc(9): error: namespace "std" has no member "rend"
      for (auto iter = std::rbegin(a); iter != std::rend(a); ++iter)
                                                    ^

#include <iterator>
#include <iostream>

int
main()
{
    int	a[] = {0, 1, 2, 3, 4, 5, 6, 7};

    for (auto iter = std::rbegin(a); iter != std::rend(a); ++iter)
	std::cout << ' ' << *iter;
    std::cout << std::endl;

    return 0;
}

 

0 Kudos
4 Replies
Yuan_C_Intel
Employee
734 Views

Hi, Toshio

Yes, this feature is not supported by Intel C++ Compiler 17.0 yet.

Please see C++14 Features Supported by Intel® C++ Compiler for an up-to-date listing of all supported features, including comparisons to previous major versions of the compiler.

Hope this helps.

Thanks.

0 Kudos
Judith_W_Intel
Employee
734 Views

 

The reason this is not supported (it is a library feature) is that in 16.0 we set the value of the __cplusplus macro to 201300L when -std=c++14 is specified whereas GNU sets it to 201402L, This causes different code in the standard library headers to be enabled.

As Yolanda's link shows this is because in 16.0 we did not fully support c++14. In 17.0 we do support all of c++14 so your code should work as expected since the value of __cplusplus matches GNU's. You should probably upgrade to the 17.0 release it you need to use the latest c++14 features.

Judy

0 Kudos
Yuan_C_Intel
Employee
734 Views

Hi, Judith

Thank you for the explanation.

It's my bad. I tried icc 17.0 with old gcc version, so that it still fails. After I switch to gcc 5.1, then use icc 17.0 it compiles the code!.

Thanks

 

0 Kudos
Toshio_U_1
Beginner
734 Views

Thank you, Yolanda and Judy. I have installed icpc-17.0 but it sill fails to compile the code;

% icpc -V

Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.0.098 Build 20160721

Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

 

% icpc -std=c++14   -c -o main.o main.cc

main.cc(9): error: namespace "std" has no member "rbegin"

      for (auto iter = std::rbegin(a); iter != std::rend(a); ++iter)

                            ^

 

main.cc(9): error: namespace "std" has no member "rend"

      for (auto iter = std::rbegin(a); iter != std::rend(a); ++iter)

So, I investigated the value of __cplusplus using the code below and found that the value is 201300 but 201402!

% icpc -V

Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.0.098 Build 20160721

Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

 

% icpc -std=c++11 main.cc  -o a.out

% a.out

201103    // OK.

 

% icpc -std=c++14 main.cc  -o a.out

% a.out

201300    // ??? Isn't it 201402?

I also investigated the value of g++-5.4.0;

% g++ -v

Using built-in specs.

COLLECT_GCC=g++

COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper

Target: x86_64-linux-gnu

Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.2' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu

Thread model: posix

gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)

 

% g++ -std=c++11 main.cc  -o a.out

% a.out

201103    // OK.

 

% g++ -std=c++14 main.cc  -o a.out

% a.out

201402    // OK.

 

#include <iostream>

int
main()
{
    std::cout << __cplusplus << std::endl;
}

 

0 Kudos
Reply