Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: VS 11, and variadic templates with std::thread  (Read 12414 times)

0 Members and 1 Guest are viewing this topic.

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
VS 11, and variadic templates with std::thread
« on: November 06, 2012, 02:50:24 am »
This is not related to SFML, but I don't belong to any other coding community so I thought I would ask here. ^_^

I am trying to start up a thread with "std::thread" like:

std::thread RunningLoadingScreen(RunLoadingScreen,CurrLoadScreen,glWindow);
 

The function looks like:

void LoadingScreens::RunLoadingScreen(LoadingScreen LS,EngineWindow& glWindow)
{
        if(LS.IsStatic){
                sf::Sprite LSS;
                LSS.setTexture(texture.getTexture(LS.ResourcePath));
                LSS.setPosition(glWindow.GetCenter().x,glWindow.GetCenter().y);
                glWindow.draw(LSS);
                glWindow.display();
        }else{
                        sfe::Movie LSM;
                        if(!LSM.openFromFile(LS.ResourcePath))
                        {
                                return;
                        }
                        LSM.setPosition(glWindow.GetCenter().x,glWindow.GetCenter().y);
                        LSM.play();
                        while(IsLoading)
                        {
                                glWindow.draw(LSM);
                                glWindow.display();
                        }
        }
}
 

But my compiler always spits the error:

Quote
std::thread::thread No overloaded function takes three arguments.

I looked it up and apparentlyVS 11 does not support Variadic Templates. So I wanted to ask if there is any way around this? I found some people mentioning the use of adding "#define" to define stuff for the preproccesor but I was unable to make out exactly what it was they were talking about, or how to do it.

So any help is as always, 100% appreciated. If you need any info just ask! :) I look forward to a great discussion.  ;D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: VS 11, and variadic templates with std::thread
« Reply #1 on: November 06, 2012, 10:45:10 am »
Easiest solution: stop using VS. ;)
I've pretty much abandoned VS since they feel like C++11 is nothing urgent...

Otherwise you can create a struct/class that hold all your wanted data and pass everything as one argument.

Btw for generic C++/programming question I can suggest to you StackOverflow. There you'll get answers quickly and often from people with quite a bit experience.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: AW: VS 11, and variadic templates with std::thread
« Reply #2 on: November 06, 2012, 03:39:46 pm »
Easiest solution: stop using VS. ;)
I've pretty much abandoned VS since they feel like C++11 is nothing urgent...

Otherwise you can create a struct/class that hold all your wanted data and pass everything as one argument.

Btw for generic C++/programming question I can suggest to you StackOverflow. There you'll get answers quickly and often from people with quite a bit experience.

What would you recommend instead of VS?

I've seen good and bad reports for netbeans, and I have also heard good things from eclipse *and use eclipse for java* but have no experience with it for C++

I've also heard mixed reports for code blocks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: VS 11, and variadic templates with std::thread
« Reply #3 on: November 06, 2012, 03:48:48 pm »
It seems that the november version of the compiler adds support for variadic templates
http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx
Laurent Gomila - SFML developer

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: VS 11, and variadic templates with std::thread
« Reply #4 on: November 06, 2012, 03:53:47 pm »
It seems that the november version of the compiler adds support for variadic templates
http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx

But if I switch my compiler, I don't think I'll be able to compile for windows XP anymore as I had it set to "Visual Studio 2012 - Windows XP (v110_xp)

>.<

I am not sure if this version of the compiler "120_CTP" includes XP support.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: VS 11, and variadic templates with std::thread
« Reply #5 on: November 06, 2012, 03:56:55 pm »
What would you recommend instead of VS?

I've seen good and bad reports for netbeans, and I have also heard good things from eclipse *and use eclipse for java* but have no experience with it for C++

I've also heard mixed reports for code blocks.
As a matter of fact Microsoft announced a CTP (customer technology previews) which should support more C++11 features a few days ago. But for a really official support it will still take longer... - Uhm Laurent was faster. :D

What to choose is a controversial topic and nearly all the arguments are just about personal preferences.
At the moment I'm using Code::Blocks to develop, but obviously not the very old official release from 2010 (iirc), but the nightly builds that come out every week or so. One just needs to download the new build and replace it with the old one, the settings etc. will all be preserved.

Personally I don't like Eclipse that much, since it's running with Java and uses quite a bit more resources than it needs to, but since I haven't really used it, I can't judge more about it. Neither can I comment on Netbeans.
If you feel like it then gVim + terminal is always a nice way, although for a new beginner not the most comfortable one.

More important than the IDE discussion is the compiler (version). I'd really like to see a working Clang compiler on Windows that comes with mostly all the essential libraries (so one could use SFML with it), but this will probably take a few more years...
So you're stuck with GCC/MinGW. The official/original MinGW32 project is a bit behind with the compiler version (4.6ish) and thus you might want to take a look at the TDM MinGW32 port. If you feel like getting a bit into a more experimental world, then you should most definitely check out the MinGW-w64 port, which reorganizes the MinGW32 project and additionally provides a 64bit compiler. But as I said the 264 project isn't the most stable and you can run into some problems which can't really get resolved atm.

What I've left out is the Cygwin vs 'native' discussion. Cygwin is a very nice to get the Linux world to Windows, but the problem is, that it's not exactly a 'native' Windows build, but you'll have to provide a Cygwin 'runtime' library. Next to this, their compiler (gcc) isn't really uptodate either. So I'd rather suggest to use MSYS. I only use Cygwin for Git interaction and other nice Linux features.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: VS 11, and variadic templates with std::thread
« Reply #6 on: November 06, 2012, 04:03:45 pm »
So an update with the Nov compiler, now I get an error telling me:

Quote
Error   1   error C3867: 'LoadingScreens::RunLoadingScreen': function call missing argument list; use '&LoadingScreens::RunLoadingScreen' to create a pointer to member

........I don't see how its missing a argument list... I passed arguments with the thread.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: VS 11, and variadic templates with std::thread
« Reply #7 on: November 06, 2012, 04:08:53 pm »
The compiler explicitely gives the solution
Quote
use '&LoadingScreens::RunLoadingScreen' to create a pointer to member
Laurent Gomila - SFML developer

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: VS 11, and variadic templates with std::thread
« Reply #8 on: November 06, 2012, 04:31:52 pm »
The compiler explicitely gives the solution
Quote
use '&LoadingScreens::RunLoadingScreen' to create a pointer to member

That leads me to this error:
Quote
Error   3   error C2064: term does not evaluate to a function taking 2 arguments   C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional   1152   1   Genesis (Microsoft Visual C++ Compiler Nov 2012 CTP)

I think my problem is in how I laid out my arguments for the thread. This is the first time I have ever touched std::thread, so I really don't know what it wants me to do at this point. Every tutorial I find online, theirs works just fine. >.>

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: VS 11, and variadic templates with std::thread
« Reply #9 on: November 06, 2012, 04:35:56 pm »
Hum, in fact they said they updated the compiler, but not the standard library. So the std::thread constructor that you want to use is probably still not available.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: VS 11, and variadic templates with std::thread
« Reply #10 on: November 06, 2012, 04:37:10 pm »
So I wanted to ask if there is any way around this?
std::bind()

Easiest solution: stop using VS.
I have yet to find an IDE that can compete with Visual Studio + Visual Assist X ;)

It seems that the november version of the compiler adds support for variadic templates
http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx
That sounds great, thanks for the information!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: VS 11, and variadic templates with std::thread
« Reply #11 on: November 06, 2012, 04:38:15 pm »
So I wanted to ask if there is any way around this?
std::bind()

Easiest solution: stop using VS.
I have yet to find an IDE that can compete with Visual Studio + Visual Assist X ;)

Bind() I have tried, it throws about 14 errors. ^^;;;;

Running it like:

std::thread RunningLoadingScreen(std::bind(&LoadingScreens::RunLoadingScreen,CurrLoadScreen,glWindow));
 

Quote
Error   3   error C2064: term does not evaluate to a function taking 2 arguments   C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional   1152   1   Genesis (Microsoft Visual C++ Compiler Nov 2012 CTP)

Running it like:
std::thread RunningLoadingScreen(&LoadingScreens::RunLoadingScreen,CurrLoadScreen,glWindow);
 

Quote
Error   3   error C2064: term does not evaluate to a function taking 2 arguments   C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\functional   1152   1   Genesis (Microsoft Visual C++ Compiler Nov 2012 CTP)

Running it like:

std::thread RunningLoadingScreen(std::bind(LoadingScreens::RunLoadingScreen,CurrLoadScreen,glWindow));
 

Quote
Error   102   error C1003: error count exceeds 100; stopping compilation.

............Not sure what to use for threading now...I really would want to use std::thread if I can, but it would seem that's a impossibility at this point.
« Last Edit: November 06, 2012, 04:42:03 pm by Flash619 »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: VS 11, and variadic templates with std::thread
« Reply #12 on: November 06, 2012, 04:41:41 pm »
Please come up with a meaningful error description if you want help. And avoid full quotes if the post is just above, even more if you refer only to a part of it.

How did you try bind()? Did you include <functional>?

Edit: Of course it is not impossible to use std::thread, you just have to do it correctly. The this pointer must be specified to bind a member function to an object, and references must be passed via std::ref. You can also use lambda expressions.
« Last Edit: November 06, 2012, 04:46:31 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: VS 11, and variadic templates with std::thread
« Reply #13 on: November 06, 2012, 04:52:03 pm »
How did you try bind()? Did you include <functional>?

The this pointer must be specified to bind a member function to an object, and references must be passed via std::ref.
In that last part.... are you talking about "std::bind" when you talk about it being specified to bind a member function?


I had seen examples of people who recommended the use of "std::bind" but was unaware of the use of "<functional>" template. I also did see some people use "std::ref" but I was, and still do not know the proper usage of it, so I stayed away from it.

Also, according to several online tutorials that I found, this is a correct method of doing it, but it seems I have to change it to different methods for VS.  Right here, is a perfectly good example that when I try to implement it for my uses, does not work. I will note however, that they did show the use of "std::bind". They also showed that it was not required but I don't think they listed what IDE/compiler they used.
« Last Edit: November 06, 2012, 04:56:19 pm by Flash619 »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: VS 11, and variadic templates with std::thread
« Reply #14 on: November 06, 2012, 05:00:00 pm »
In that last part.... are you talking about "std::bind" when you talk about it being specified to bind a member function?
Yes, I spoke about std::bind and the fact that you have to pass the this pointer of the object on which you want to call the member function.

I had seen examples of people who recommended the use of "std::bind" but was unaware of the use of "<functional>" template.
<functional> is a header, as the word "include" suggests.

I also did see some people use "std::ref" but I was, and still do not know the proper usage of it, so I stayed away from it.
A better idea would be to learn it ;)
See the documentation of Boost.Bind, for example.

By the way, instead of bind(), you can achieve the same functionality with a functor (=function object). It is simpler if you don't know the standard library functionals, but it requires more code.
« Last Edit: November 06, 2012, 05:04:07 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything