Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
raminasi
Jan 25, 2005

a last drink with no ice

Ari posted:

Disagree. Some of it can be confusing if you're not familiar with either the programming or mathematical concepts involved, but Boost is spread wide over many different ideas, and a lot of the time it just simplifies existing stdlibc++ functionality through syntactic sugar (think boost/foreach.hpp). Parts of Boost is taught in a lot of introductory C++ classes both in high school and college, and for good reason - for the most part, it's good for you.

The STL higher-order algorithms in particular are a pain in the rear end without boost::bind.

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Ari posted:

Disagree. Some of it can be confusing if you're not familiar with either the programming or mathematical concepts involved, but Boost is spread wide over many different ideas, and a lot of the time it just simplifies existing stdlibc++ functionality through syntactic sugar (think boost/foreach.hpp). Parts of Boost is taught in a lot of introductory C++ classes both in high school and college, and for good reason - for the most part, it's good for you.

This is not really a good idea. Using Boost from the start is just a good way of learning C++ by rote. Until you at least conceptually understand templates, you should limit your use of Boost to the absolute minimum. God help you if you mistype anything; your compiler will explode at you. Obviously you don't need to know all the gooey bits, but without a basic understanding of templates, you're forced to rely on memorization and help from other people when you end up with a 200-line template error backtrace.

Avenging Dentist fucked around with this message at 18:52 on Mar 29, 2010

That Turkey Story
Mar 30, 2003

As someone who uses Boost every day in very large doses and looks at it as probably the greatest collection of generic libraries that exists, I wouldn't recommend it to a newcomer, especially concerning bind, lambda, phoenix, etc. As was pointed out, they are fantastic but many of the libraries involve syntactical dances that would likely seem unintuitive to someone who doesn't have at least a basic understanding of the more subtle rules of C++ and how the libraries work. As AD said, one slight mistake and you may face hundreds/thousands of lines of compile errors that can be difficult for both an inexperienced and an experienced programmer to figure out. I suppose I could pull back my statement a bit and say yes, there are a few Boost libraries that are fine for someone new to the language, but as for the libraries mentioned above and the solution I mentioned in my other post, I think a newcomer to C++, regardless of background, would not have a sufficient understanding of the language to grasp what's going on and would spend too much time battling compile errors and using tools whose specifics are well beyond his comprehension.

txrandom
Aug 3, 2007
Are there any free, Windows/Visual Studio buffer overflow detectors?

POKEMAN SAM
Jul 8, 2004

txrandom posted:

Are there any free, Windows/Visual Studio buffer overflow detectors?

I think that this guy can detect buffer overflows: http://www.microsoft.com/downloads/details.aspx?FamilyID=c4a25ab9-649d-4a1b-b4a7-c9d8b095df18&displaylang=en

raminasi
Jan 25, 2005

a last drink with no ice

That Turkey Story posted:

As someone who uses Boost every day in very large doses and looks at it as probably the greatest collection of generic libraries that exists, I wouldn't recommend it to a newcomer, especially concerning bind, lambda, phoenix, etc. As was pointed out, they are fantastic but many of the libraries involve syntactical dances that would likely seem unintuitive to someone who doesn't have at least a basic understanding of the more subtle rules of C++ and how the libraries work. As AD said, one slight mistake and you may face hundreds/thousands of lines of compile errors that can be difficult for both an inexperienced and an experienced programmer to figure out. I suppose I could pull back my statement a bit and say yes, there are a few Boost libraries that are fine for someone new to the language, but as for the libraries mentioned above and the solution I mentioned in my other post, I think a newcomer to C++, regardless of background, would not have a sufficient understanding of the language to grasp what's going on and would spend too much time battling compile errors and using tools whose specifics are well beyond his comprehension.

Even simple cases of bind?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The STL does have bind1st and bind2nd.

raminasi
Jan 25, 2005

a last drink with no ice

Plorkyeran posted:

The STL does have bind1st and bind2nd.

Yeah, and they're much more awkward to use than boost::bind.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

GrumpyDoctor posted:

Even simple cases of bind?

Have you seen a compiler error from bind? It's absolutely awful, and even I end up glazing over it.

Vanadium
Jan 8, 2005

B-but... concepts...

:smithicide:

floWenoL
Oct 23, 2002

Do you guys know about the upcoming improvements to C++ listed here? What do you guys think?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
They're awesome and fix most of my complaints with the language. I can't wait for a compiler to implement them.

Vinterstum
Jul 30, 2003

floWenoL posted:

Do you guys know about the upcoming improvements to C++ listed here? What do you guys think?

What's scary is that nr. 1 actually made some degree of sense to me.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
Nasty template metaprogramming question: Is there any way (either in current C++ or C++0x) through templates to extract the argument types of a function or operator() of a function object?

I've got something working in the case of a function with a single argument:

code:
template <typename T>
struct domain_traits { };

template <typename T>
struct domain_traits<T (*)(T)>
{
	typedef T type;
};

template <typename F>
typename domain_traits<F>::type foo(F f, typename domain_traits<F>::type x) { ... do something with f(x) ... }

int f(int x) { return x + 1; }

int main()
{
    foo(f, 0); // the second argument to foo is correctly deduced as int
    foo(f, ""); // error: invalid conversion from 'const char*' to 'int', as expected
}
First: I'm having trouble extending this to function objects, since I don't know how to extract the parameter types from the operator() method; a function pointer is easy because I can specialize on its actual type, "T (*)(T)". Am I going to just have to explicitly provide an appropriate typedef in any function object I want to use in this context?

Second: Can this be generalized to n-ary functions/function objects, making it possible to extract the type of the i-th argument for some arbitrary i?

I just finished reading Elements of Programming and it's got me thinking about stuff like this :v:

EDIT: Ah, Boost, of course; I just discovered <boost/function_types/parameter_types.hpp>. Now to see how difficult it would be to pull that functionality out of the rest of Boost, for purely academic purposes...

Flobbster fucked around with this message at 02:10 on Mar 30, 2010

Vomik
Jul 29, 2003

This post is dedicated to the brave Mujahideen fighters of Afghanistan
I've been teaching myself C++, mostly for hobby but also to eventually expand it into my work. I am almost finished with Accelerated C++, and the following link from the OP: http://www.parkscomputing.com/cppwiki/index.php?title=List_of_recommended_books recommends that I buy "Pro Visual C++/CLI and the .NET 2.0 Platform."

Well, I know that is pretty old, and I did find a newer version on Amazon for .NET 3.5 (although I believe 4.0 should be out soon...) but I also read the C++ FAQ that is listed in the OP and I feel like maybe I should just skip to the Effective C++ books.

I guess I have a few questions:

1. What is the C++/CLI thing? Is that just a Microsoft implementation? Am I limiting myself by learning that, or is that an irrelevant question? If I buy this book and learn the .NET platform is that going to detract from my learning actual C++? I'm on Windows and have been using Visual Studio 2010 beta while working through Accelerated C++.

2. Are there other books that people would recommend instead? I suppose at this point my options are either continue down this list of recommended books, or just buy the C++ Primer and Effective C++ and read/understand those.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Flobbster posted:

EDIT: Ah, Boost, of course; I just discovered <boost/function_types/parameter_types.hpp>. Now to see how difficult it would be to pull that functionality out of the rest of Boost, for purely academic purposes...

Quite easy (let's just do binary C functions that don't return void in C++03):

code:
template <class R, class A1, class A2>
struct binary_traits<R(*)(A1,A2)>
{
    typedef R result_type;
    typedef A1 first_argument_type;
    typedef A2 second_argument_type;
};
(Stolen from http://www.boost.org/doc/libs/1_42_0/boost/functional.hpp)

You should be able to generalize this pretty easily, and the C++0x variadic version isn't too hard either.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Vomik posted:

1. What is the C++/CLI thing? Is that just a Microsoft implementation? Am I limiting myself by learning that, or is that an irrelevant question? If I buy this book and learn the .NET platform is that going to detract from my learning actual C++? I'm on Windows and have been using Visual Studio 2010 beta while working through Accelerated C++.

It's C++ with .NET. Obviously this only works when you're using .NET, and I really wouldn't recommend it. Honestly, I should probably put up better recommendations than that link (it's kinda old and sucky).

Vomik posted:

2. Are there other books that people would recommend instead? I suppose at this point my options are either continue down this list of recommended books, or just buy the C++ Primer and Effective C++ and read/understand those.

Effective C++ is probably good. I'm not really the best person to ask since I learned purely by programming in C++ a lot. Honestly, depending on the type of learner you are, that might be the best route.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Avenging Dentist posted:

Quite easy (let's just do binary C functions that don't return void in C++03):

code:
template <class R, class A1, class A2>
struct binary_traits<R(*)(A1,A2)>
{
    typedef R result_type;
    typedef A1 first_argument_type;
    typedef A2 second_argument_type;
};
(Stolen from http://www.boost.org/doc/libs/1_42_0/boost/functional.hpp)

You should be able to generalize this pretty easily, and the C++0x variadic version isn't too hard either.

Ah, I had a minor brain fart on the syntax, forgetting that no matter how many parameters I declare in template<...>, I'm only passing the single function pointer type into the instantiation.

But in the case of using a function object instead of a function pointer, it looks the only solution is to explicitly have the function object type declare typedefs first_argument_type, second_argument_type, etc., since I can't specialize on the signature of operator() like I can on something like R(*)(A1,A2)?

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Vomik posted:

1. What is the C++/CLI thing? Is that just a Microsoft implementation? Am I limiting myself by learning that, or is that an irrelevant question? If I buy this book and learn the .NET platform is that going to detract from my learning actual C++? I'm on Windows and have been using Visual Studio 2010 beta while working through Accelerated C++.
C++/CLI is a dialect of C++ that compiles to the .net platform and has nonstandard features to use some of the features of that platform.

It's a marketing gimmick as far as I can tell. If you want to develop .net applications, you will get the best support by using C# or VB.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Flobbster posted:

But in the case of using a function object instead of a function pointer, it looks the only solution is to explicitly have the function object type declare typedefs first_argument_type, second_argument_type, etc., since I can't specialize on the signature of operator() like I can on something like R(*)(A1,A2)?

You might be able to do it, but it will play havoc with multiple overloads of the call operator.

Vinterstum
Jul 30, 2003

Gazpacho posted:

C++/CLI is a dialect of C++ that compiles to the .net platform and has nonstandard features to use some of the features of that platform.

It's a marketing gimmick as far as I can tell. If you want to develop .net applications, you will get the best support by using C# or VB.

The main usage (intended by MS or not) of C++/CLI is mostly when you have a lot of old C++ code laying around and you want to migrate to .Net. I wouldn't say it's a marketing gimmick, you don't really hear MS mention it much.

Vomik
Jul 29, 2003

This post is dedicated to the brave Mujahideen fighters of Afghanistan

Gazpacho posted:

C++/CLI is a dialect of C++ that compiles to the .net platform and has nonstandard features to use some of the features of that platform.

It's a marketing gimmick as far as I can tell. If you want to develop .net applications, you will get the best support by using C# or VB.

Avenging Dentist posted:

It's C++ with .NET. Obviously this only works when you're using .NET, and I really wouldn't recommend it. Honestly, I should probably put up better recommendations than that link (it's kinda old and sucky).


Effective C++ is probably good. I'm not really the best person to ask since I learned purely by programming in C++ a lot. Honestly, depending on the type of learner you are, that might be the best route.

All right, I think I'm going to skip anything C++/CLI related, and pick up Effective C++ and C++ Primer. Just to double-check I can continue to use Visual Studio for learning regular C++ right? As long as I don't access any of the CLI libraries (or whatever.)

Also, you're right Avenging Dentist. I probably should just start actually programming something, but I'm mostly worried about learning bad practices. Maybe I'll start actually working on the things I have as my end-goal anyway.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Avenging Dentist's Official Guide to Becoming an Awesome Programmer:
  1. Pick a wildly overambitious project
  2. Work on it until you write yourself into a corner
  3. Fail
  4. Learn from your failure
  5. Repeat

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Avenging Dentist posted:

Avenging Dentist's Official Guide to Becoming an Awesome Programmer:
  1. Pick a wildly overambitious project
  2. Work on it until you write yourself into a corner
  3. Fail
  4. Learn from your failure
  5. Repeat

Hint: works best when you have time to fail repeatedly in rapid succession.

awesmoe
Nov 30, 2005

Pillbug
Effective C++ (and the other ones you should read, effective STL and exceptional C++) aren't much use until you've actually done quite a lot of programming. I guess you can buy them and read them and then understand them in a couple of years :)

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

niteice posted:

Hint: works best when you have time to fail repeatedly in rapid succession.
also if you don't get discouraged by massive failure

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Dijkstracula posted:

also if you don't get discouraged by massive failure

Saturday-afternoon Special as it sounds, every time I've failed in a project, I've learned an awful lot about design (way more than I've learned from books). It's difficult to learn good design except to get burned by bad designs, but once you've learned it, you can basically do anything.

awesmoe
Nov 30, 2005

Pillbug

Avenging Dentist posted:

Saturday-afternoon Special as it sounds, every time I've failed in a project, I've learned an awful lot about design (way more than I've learned from books). It's difficult to learn good design except to get burned by bad designs, but once you've learned it, you can basically do anything.

That's kind of what I like about the effective/exceptional books. They give good, justified solutions to problems which come up pretty often - solutions that aren't easy to get right yourself (for example, the exception safe stack worked-ad-nauseum example).
So if you've been programming for a few years, they're good to look through and see alternative solutions to problems you've no doubt come across.

Contero
Mar 28, 2004

Has anyone ever dealt with changing layouts in Qt? I want to change between two different layouts, and they aren't as simple as swapping vertical alignment with horizontal alignment. I have nested layouts with spacers and two widgets I don't want to destroy every time the layout changes. I have pointers to these widgets, but I haven't been able to reparent them successfully.

I'd have thought this would be a standard feature for Qt but I've gone through the documentation and searched the mailing lists and can't seem to find a good answer or one that isn't as painful as having to reconstruct all of my widgets every time I want something to change position. Please tell me I'm just missing something obvious.

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
C++ newbie, can anyone tell me why this line:

code:
vector<int> proj (0, 0, 0);
would give me the following error message in Visual C++:
code:
main.cpp(169) : error C2664: 'std::vector<_Ty>::vector<int>(_Iter,_Iter,const 
std::allocator<_Ty> &)' : cannot convert parameter 3 from 'int' to 'const std::allocator<_Ty> &'

Contero
Mar 28, 2004

Stavros posted:

C++ newbie, can anyone tell me why this line:

code:
vector<int> proj (0, 0, 0);
would give me the following error message in Visual C++:
code:
main.cpp(169) : error C2664: 'std::vector<_Ty>::vector<int>(_Iter,_Iter,const 
std::allocator<_Ty> &)' : cannot convert parameter 3 from 'int' to 'const std::allocator<_Ty> &'

std::vector is a resizable array of objects, not a geometry vector.

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again

Contero posted:

std::vector is a resizable array of objects, not a geometry vector.

Oops you're right. I guess I meant to do proj.push_back(0) instead. Thanks.

OddObserver
Apr 3, 2009

Contero posted:

Has anyone ever dealt with changing layouts in Qt? I want to change between two different layouts, and they aren't as simple as swapping vertical alignment with horizontal alignment. I have nested layouts with spacers and two widgets I don't want to destroy every time the layout changes. I have pointers to these widgets, but I haven't been able to reparent them successfully.

I'd have thought this would be a standard feature for Qt but I've gone through the documentation and searched the mailing lists and can't seem to find a good answer or one that isn't as painful as having to reconstruct all of my widgets every time I want something to change position. Please tell me I'm just missing something obvious.

QWidget::setLayout says to delete the previous layout (on the container, that is) to be able to set the new one. QLayout::addChildWidget can also move things around layouts, but whines doing that (and is documented as such). Looking around the code suggests that should work.

schnarf
Jun 1, 2002
I WIN.

Stavros posted:

Oops you're right. I guess I meant to do proj.push_back(0) instead. Thanks.
And maybe you're not intending to do this, but if you want a datatype to hold a vector in R3, make a datatype for it, don't use std::vector; that's not what it's for.

Contero
Mar 28, 2004

OddObserver posted:

QWidget::setLayout says to delete the previous layout (on the container, that is) to be able to set the new one. QLayout::addChildWidget can also move things around layouts, but whines doing that (and is documented as such). Looking around the code suggests that should work.

Well deleting a layout deletes all of its children, in this case my widgets that I don't want deleted. I've tried to reparent them to a temporary widget then add them again but I don't think it worked. Maybe I was doing things in the wrong order.

I could probably make some sort of smart pointer wrapper around QWidget, but it seems like a bit of a hack to do something that should be in Qt by default.

OddObserver
Apr 3, 2009

Contero posted:

Well deleting a layout deletes all of its children, in this case my widgets that I don't want deleted.
Did you test that, or are just assuming? I was concerned about the same thing, and glance through destructors... didn't seem like it was actually destroying them.

quote:

I've tried to reparent them to a temporary widget then add them again but I don't think it worked. Maybe I was doing things in the wrong order.

I could probably make some sort of smart pointer wrapper around QWidget, but it seems like a bit of a hack to do something that should be in Qt by default.

Well, moving them to the new layout (adding it to them) may work, but will likely spam the terminal with warnings. I am quite surprised but what you're doing, though, hard to picture what it'd be good for --- all scenarios I can think of can probably be handled by just using a QStackedWidget or something.

Vomik
Jul 29, 2003

This post is dedicated to the brave Mujahideen fighters of Afghanistan

Stavros posted:

C++ newbie, can anyone tell me why this line:

code:
vector<int> proj (0, 0, 0);
would give me the following error message in Visual C++:
code:
main.cpp(169) : error C2664: 'std::vector<_Ty>::vector<int>(_Iter,_Iter,const 
std::allocator<_Ty> &)' : cannot convert parameter 3 from 'int' to 'const std::allocator<_Ty> &'

If you want to declare an int vector with 3 indices = 0, then vector<int> proj(3,0) will do that... I don't know if that is necessarily the best thing you want to do for your purpose though. In fact, just proj(3) should do it because I think the default value for int is 0.

Optimus Prime Ribs
Jul 25, 2007

Quick pointers question.

Given the following code:
code:
int* ptrA;
int* ptrB;
int* ptrC;

ptrA = ptrB = ptrC = NULL;
Does that mean:
- ptrA, ptrB, and ptrC point to NULL values?
- ptrA points to ptrB, which points to ptrC, which points to NULL value?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Assignment is right-associative, so a = b = c is the same as a = (b = c)

Adbot
ADBOT LOVES YOU

Optimus Prime Ribs
Jul 25, 2007

Ahh that makes sense.
I was worried I was doing some really stupid with that line of code.

Thanks, chief. :hfive:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply