How to use tr1 with Visual Studio 2010 (tr1::function)?
Asked Answered
L

2

8

How does one start using the tr1 features of Visual Studio 2010? For a more specific case, I require the std::tr1::function. I tried including #include <tr1/functional> which reports as missing, while #include <functional> includes fine, but when I set this:

std::tr1::function<void(void)> callback;

I get:

1>d:\marmalade\projects\core\src\button.h(21): error C3083: 'tr1': the symbol to the left of a '::' must be a type
1>d:\marmalade\projects\core\src\button.h(21): error C2039: 'function' : is not a member of '_STL'
1>d:\marmalade\projects\core\src\button.h(21): error C2143: syntax error : missing ';' before '<'
1>d:\marmalade\projects\core\src\button.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\marmalade\projects\core\src\button.h(21): error C2238: unexpected token(s) preceding ';'

If I use boost, it works fine, but for this project, because of using a specific framework I'd require the Visual Studio tr1 version.

As suggested, skipping the tr1, still returns the same result:

std::function<void(void)> callback;

1>d:\marmalade\projects\core\src\button.h(20): error C2039: 'function' : is not a member of '_STL'
1>d:\marmalade\projects\core\src\button.h(20): error C2143: syntax error : missing ';' before '<'
1>d:\marmalade\projects\core\src\button.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\marmalade\projects\core\src\button.h(20): error C2238: unexpected token(s) preceding ';'
Licastro answered 1/5, 2012 at 19:14 Comment(20)
tr1 stands for Technical Report 1 which was a list of proposed additions to the C++ Standard. Once the proposals were accepted, the tr1 designation became obsolete.June
did you include <functional>?Etamine
The error says functional is not a member of _STL. Are you sure you wrote std::function, and not std::functional?Joaquin
Copied the wrong error. I tried both versions, both with the same result.Licastro
@Licastro : Do you have #define std _STL somewhere? Because that error makes no sense for the code you've shown.Kohn
No, I do not. However if I put that in, I get a completely third error saying I am redefining std.Licastro
@Speed: Works for everyone else: ideone.com/9gd3N, there's something missing that you haven't told us. Especially since your compiler seems to think someone redefined std as a variable of type _STL.Etamine
It may be the library. I am using a library called Marmalade with it. It may tinker with the settings of the project...Licastro
Comment out all the includes except functional includes, and see if the errors go away on the line with the std::function. If so, you know it's a header causing the problem.Etamine
@Licastro If you put that macro in and get an error that you're redefining std, that means someone, somewhere already does #define std. Put #undef std after your includes, then find and shoot whoever defined std as a macro.Kohn
to help with ildjarn's guess: CTRL+SHIFT+F. Find: "define std", Look in: "Entire Solution"Etamine
There is no matches as I do not do that in the code. I think the library madewithmarmalade.com is using a modified compiler...Licastro
@Licastro : Did you or did you not try #undef std?Kohn
@Speed: Did you try commenting out various headers to see which is causing the functional issue?Etamine
undefining std breaks strings and vectors. Marmalade tinkers with those classes. I am sure of it...Licastro
@Speed: madewithmarmalade.com/marmalade/benefits/… says they compile with Visual C++Etamine
They do, but the Visual Studio project gets generated by their bat file.Licastro
waaaaaiiiit, Does Marmalade provide it's own standard library? I think it does. That would explain the lack of newer features, like function.Etamine
madewithmarmalade.com/devnet/forum/4994 I guess so.Licastro
I'll try taking the std::function files and put them directly into my source folder... Thank you for your time :(Licastro
E
8

Based on your comments, and on this page, I think that Marmalade comes with it's own STL implementation, that appears out of date. This page verifies that they use a version of STLPort, that does not support the TR1 that came out in 2005, much less anything newer. Your options are:

1) Copy/write those yourself
2) Do without
3) Download a newer version of STLPort. It doesn't seem to have been updated in the last two years, so no C++11, but they do mention having functional, but aren't clear as to if it's in the std or std::tr1 namespace. However, this might not work with Marmalade, so make backups and be careful.

Etamine answered 1/5, 2012 at 19:57 Comment(4)
I think it's just bundled with STLPort (source)... Terrible.Kohn
@Speed: Updated answer, a newer version of STLPort may or may not help you.Etamine
Thank you for the extended help. I really appreciate it!Licastro
Why on earth would you a library do something like that?Gosh
G
2

Visual Studio 2010 ships with C++11 enabled by default (or at least what is implemented). You need to use std::function<void(void)>.

For a complete table see here.

As an aside: You shouldn't use anything from TR1 nowadays. It has been integrated into the new standard.

Gosh answered 1/5, 2012 at 19:18 Comment(2)
Regardless, I still get the exact same error. std::function<void(void)> callback; returns the exact error, without the first one: error C2039: 'function' : is not a member of '_STL'Licastro
@Licastro This looks highly suspicious. grep for any strange defines.Gosh

© 2022 - 2024 — McMap. All rights reserved.