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

Templates, Boost tuples & Three compilers

alexvi
Beginner
269 Views
Hi,

Here is some program.

It was compiled with three compilers.


BOOST Version: 1_34

--- HP-UX, aCC ---
aCC: HP C/aC++ B3910B A.06.15 [May 16 2007]

> aCC +DD64 -AA -I/adjhome/ip/ccadj/ccadj/BOOST/boost_1_34_0 prog1.cpp
// No errors


--- AIX, xlC ---
IBM XL C/C++ Enterprise Edition V8.0 for AIX

xlC_r -q64 -qwarn64 -I/usr/local64/boost_1_34_0 prog1.cpp
// No errors


--- Linux, icpc ---
Intel C++ Intel 64 Compiler Professional for applications running on Intel 64, Version 11.0

> icpc -I/adjhome/adj/ccadj/ccadj/BOOST/boost_1_34_0 prog1.cpp
prog1.cpp(47): error: expected an expression
v.push_back (t.get());
^

prog1.cpp(62): error: expected an expression
v.push_back (t.get<0>());
^
detected during instantiation of "std::vector<:TUPLES::ELEMENT><0, T>::type, std::allocator<:TUPLES::ELEMENT><0, T>::type>> Foo::tuple2vector(const T &) [with T=boost::tuples::tuple, I=1UL]" at line 80

compilation aborted for prog1.cpp (code 2)



--------------
Something is wrong?

Thanks.

Alex Vinokur


========= prog1.cpp =========
#include
#include
#include
#include
#include
#include

// ----------------------------------------
template<:SIZE_T n=""> struct uniform_tuple;

template
struct uniform_tuple<1,T>
{
typedef typename boost::tuple type;
};

template
struct uniform_tuple<2,T>
{
typedef typename boost::tuple type;
};


template
struct uniform_tuple<3,T>
{
typedef typename boost::tuple type;
};

template
struct uniform_tuple<4,T>
{
typedef typename boost::tuple type;
};


// --------------------------------------
template
class Foo
{
BOOST_STATIC_ASSERT (I < boost::tuples::length::value);
public:
typedef typename boost::tuples::element<0,T>::type LocalType;
static std::vector tuple2vector (const T& t)
{
std::vector v = Foo::tuple2vector(t);
v.push_back (t.get());
return v;
}

};


template
class Foo
{
public:
typedef typename boost::tuples::element<0,T>::type LocalType;
static std::vector tuple2vector (const T& t)
{
std::vector v;
v.push_back (t.get<0>());
return v;
}

};

// --------------------
template
class DoIt : public Foo::value - 1>
{
};



int main(void)
{
typedef uniform_tuple<2, int>::type Tuple2;
std::vector v;
v = DoIt::tuple2vector(boost::tuples::make_tuple (100, 200));

for (std::size_t i = 0; i < v.size(); i++)
{
std::cout << v << " ";
}
std::cout << std::endl;

return 0;
}

=============================
0 Kudos
3 Replies
JenniferJ
Moderator
269 Views
what version of icc are you using? The output shows 11.0. But which package?

I tried only on Windows so far, it can be compiled fine with 11.0.074 or 11.1 or Parallel Composer.

Jennifer
0 Kudos
alexvi
Beginner
269 Views
what version of icc are you using? The output shows 11.0. But which package?

I tried only on Windows so far, it can be compiled fine with 11.0.074 or 11.1 or Parallel Composer.

Jennifer


1. > icpc -V
Intel C++ Intel 64 Compiler Professional for applications running on Intel 64, Version 11.0 Build 20090318 Package ID: l_cproc_p_11.0.083
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.

By the way, is it possible to get Intel Compiler package within C/C++ program?
Neither __INTEL_COMPILER, nor __INTEL_COMPILER_BUILD_DATE contain package number.

2. The question answered in http://groups.google.com/group/comp.lang.c++/msg/0f91ee0ecf02d640 :
Use v.push_back (t.template get()); instead of v.push_back (t.get());

Thanks.
0 Kudos
JenniferJ
Moderator
269 Views
Quoting - alexvi

2. The question answered in http://groups.google.com/group/comp.lang.c++/msg/0f91ee0ecf02d640 :
Use v.push_back (t.template get()); instead of v.push_back (t.get());

Thanks.

From our compiler engineer the code "v.push_back(t.get());" is not correct according to C++ standard. It's why our compiler gives error. So this is not a compiler bug.

Thanks!

Jennifer
0 Kudos
Reply