Jump to content
  • Advertisement
Sign in to follow this  
rozz666

std::forward

This topic is 3772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Where is this function defined? The one with variadic templates. It's not part of ConceptGCC. I used google and found some referencees to it, but not where it comes from.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by rozz666
Where is this function defined?

I wasn't paying attention when all that move-semantics stuff came through the lists but I believe it's one of those things built in to the compiler (ie. it can't be implemented in the library proper but requires compiler support). I don't know if there are version of GCC with built-in support out in the wild, other than what you can grab from SVN.

Share this post


Link to post
Share on other sites
I found a definition :-) It's not built into the compiler, but it needs rvalue references.


namespace std {

template <typename T>
struct identity
{
typedef T type;
};

template <typename T>
inline T&& forward(typename identity<T>::type&& a)
{
return a;
}

template <typename T>
inline typename remove_reference<T>::type&& move(T&& a)
{
return a;
}
}


But I don't understand what std::identity does, or rather what it does in the context of std::forward.

At last we have perfect forwarding :-)


template <typename T, typename... Args>
std::shared_ptr<T> create_ptr(Args&&... args)
{
return std::shared_ptr<T>(new T(std::forward<Args>(args)...));
}

int main()
{
create<std::pair<int, std::vector<float>>>(5, std::vector<float>(10));
}


Don't you just love variadic templates? Too bad it takes ages to compile.

Share this post


Link to post
Share on other sites
Quote:
Original post by rozz666
Don't you just love variadic templates? Too bad it takes ages to compile.

what compiler are you using - trunk version of gcc ?

Share this post


Link to post
Share on other sites
Quote:
Original post by rozz666
Don't you just love variadic templates? Too bad it takes ages to compile.


Definitely some cool stuff.

Heavily templated code has always seemed to take a while to compile. I expect that these early implementations of c++0x just need some time to be improved upon :)

Share this post


Link to post
Share on other sites
chairthrower: I'm using latest version of ConceptGCC.

godecho: I believe so. They are rewriting the SC++L using concepts and they say the compiler is not optimized.

Share this post


Link to post
Share on other sites
Quote:
Original post by rozz666
I found a definition :-) It's not built into the compiler, but it needs rvalue references.

Is that the definition in bits/stl_move.h ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Bregma
Quote:
Original post by rozz666
I found a definition :-) It's not built into the compiler, but it needs rvalue references.

Is that the definition in bits/stl_move.h ?


Hmm, I don't have this file. What version do you have? I downloaded mine (Cygwin x86) yesterday from here http://www.generic-programming.org/software/ConceptGCC/download.php .

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!