Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

93 Neutral

About loufoque

  • Rank

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. loufoque

    [C++] swap

    Yes, there were some debates (that's what a committee is for), but it was the initial solution that was finally accepted. Also, your summary is inaccurate and altered the content in a biased way to make it look like ADL is bad. Quote:The standards committee is majorly delaying the next standard because they don't feel concepts are yet up to snuff. This isn't a lightly made decision. They don't want to fuck up, and are seriously concerned that concepts as currently envisioned, and quite possibly their reliance on ADL for shenanigans like this, could be a fuck up. The reasons concepts were removed have nothing to do with ADL, but were concerns about explicit concepts, concept maps, and the complexity of implementing the whole system. Quote:That's not an option for you anymore. Your options are (1) backup your statements with sources or (2) get banned. I did, several times, with much more explanation than needed. In any case, banning me because you don't agree would be stupid, but such stupidity doesn't really surprise me coming from here. I guess there is really no chance in evangelizing the community of game developers into writing less horrid C++. At least I tried.
  2. loufoque

    [C++] swap

    When I talked of the standard, I was referring to the standardization initiative in general, not the pristine C++03 ISO standard. Here is better evidence for those having trouble: C++03 doesn't mandate it, and it is a defect of the previous standard that is fixed by that resolution. Note that there are numerous defects in the previous standards that were later clarified and resolved; and implementers follow those resolutions in their C++03 implementation. Note "concept" here refers to informal concepts, not the C++0x mechanism that was removed. Quote:Concepts are being removed from what will be C++1x. Irrelevant to the question at hand. The latest draft, namely N2914, still contains concepts as those have not been removed yet, as this takes time. In any case, that doesn't change anything at all; whether the concepts are informal or statically checked doesn't change anything. Quote:So you're saying we shouldn't specialize std::swap because the standard after the next may imply to you that ADL is your god and savior. The intention of the standard that ADL is used for swap predates C++0x and has been there for a long time. If you don't want to believe, then don't; do as you like, I could care less. I'm just trying to help you guys use the language they way it's supposed to be used here. Quote:and seeing as how C++0x has become C++1x C++0x is still the name most people use, irrelevant of whether it is released before 2010 or not. The running joke is that it's actually in hexadecimal, allowing it to go as high as 2015. C++1x is also accepted, but that's the one that is the less used. Quote:Edit2: Lofuque - boost::swap is not implemented like that. It doesn't infinitely recurse for a start. Yes it's not implemented like this, this was used for simplification. And my implementation doesn't recurse infinitely as far as I can see. Either there is an overload in associated namespace of T1 or T2, and that overload is called, or there is not and std::swap is called. The case where the associated namespace of T1 or T2 is boost would lead to ambiguity, not infinite recursion, if only boost::swap wasn't specially designed to be a worse match than std::swap or a specific overload by having two type parameters instead of one. Quote:recommended by Scott Meyers (Modern C++) You're aware that while Scott Meyers is pretty good at writing, he's no C++ guru? He certainly is no authoritative figure. Quote:If you have a type that's fast to swap, but slow to assign (again, std::vector), you either have a design fault (not always!) or something that probably shouldn't be sorted. Algorithms, or indeed almost all of the standard, don't have to adhere to jack when it comes to the nitty-gritty of the implementations, as long as they conform. That should just be common sense. Swap is a two-way move, assign copies. Of course assignment is much more costly than swap. Also, a swappable type is not necessarily movable nor copiable. That comment is even more silly than the whole swap in std thing. [Edited by - loufoque on September 1, 2009 8:44:10 AM]
  3. loufoque

    [C++] swap

    Quote:I just searched through my copy of the standard, checking every mention of "swap" in the standard, and found no mention of this at all. The current version of the C++0x draft, which is still concept-based, uses concepts instead of ADL, as concepts were made to have similar properties to that of ADL. As you can see, it makes use of a Swappable concept that is defined as a type which has a swap(T&, T&) overload visible in its namespace, which is quite equivalent. Similarly, the Range concept, upon which the new for-loop depends, is being reworked so that it uses ADL to find begin and end. Quote:While the second and third sentences imply, to me, that you may partially specialize things in the std namespace to your hearts content... as long as those specializations have external linkage and meet the other requirements of the standard library. Please also note that overloading isn't the same thing as explicit specialization. The point was that the standard doesn't allow overloading in the std namespace, which is required to define swap generically. Your preprocessing solution is of course not generic, since any new instantiation of your template for different types that those you listed won't work.
  4. loufoque

    C++ Pointer Theory

    Quote:Actually, you don't even have to resort to assembly. I've found that just picking up any old C book will quickly get to used to using pointers since they are everywhere in C it seems. C students have as many problems understanding pointers, and arrays as well, as C++ ones. A C++ programmer should fully know C anyway, since it's mostly part of the language.
  5. loufoque

    [C++] swap

    Quote:Also, the Wikipedia article on ADL mentions that over-dependence on it can lead to semantic problems. Yes, and that's totally irrelevant. swap is a particular case, a customization point, and the standard explicitly says to rely on ADL for that one.
  6. loufoque

    Removing from a std::vector

    A delete outside of a destructor. An obvious indication that your code is not exception-safe.
  7. loufoque

    C++ Pointer Theory

    I found that the best way to make students grasp pointers is to make them code in assembly. You may want to try that if you want to further your understanding.
  8. This is the type of thing virtual inheritance was made for.
  9. loufoque

    [C++] swap

    The wikipedia page on ADL, on top of explaining what ADL is, also shows how to use it with swap. Quote:Unfortunately there are "broken" implementations out there, e.g VC++ 2005's iter_swap: Interfacing with broken implementations is out of the scope of good C++ practices IMHO. (MSVC9 appears to have fixed it, by the way)
  10. loufoque

    [C++] swap

    No, you shouldn't invoke std::swap, this obviously doesn't perform ADL. Don't worry, your STL implementation performs ADL as well, since the call to swap won't be qualified. If you don't want to follow the standard guidelines and do silly things by putting your overload or specialzation in the std namespace, that's up to you. But ADL is the way for these things to work, just like operator overloading or begin/end for C++0x ranges.
  11. loufoque

    [C++] swap

    That website is wrong. swap, like other customization points, is supposed to be picked up by ADL (Koenig lookup). So you should overload it in the namespace your type is in. You might want to invoke it using boost::swap, which is implemented as namespace boost { template<typename T1, typename T2> void swap(T1& t1, T2& t2) { using std::swap; swap(t1, t2); } } [Edited by - loufoque on August 29, 2009 3:23:03 PM]
  12. loufoque

    Multithreading in a game & boost

    Quote:How should this be handled? Instead of letting main thread endlessly checking A's status while it is doing its main job, for example, you may use boost::condition for A thread to notify the main thread once A is done with its task. That's not how condition variables work. The main thread would have to wait on the condition variable, and thus block, to receive the notification.
  13. You can directly write if(int err = someFunc()) // someFunc returns 0 on success { indicateError(err); } if(Pigeon* p = dynamic_cast<Pigeon*>(someBird)) { p->doPigeonStuff(); }
  14. loufoque

    [C++0x] enum class

    Quote:Well yea but just the wording made it sound like it's been in for a super long time and should be stable. 4.4 is the latest production release, so it wouldn't be a big surprise if a certain C++0x feature that was introduced in that release wasn't working correctly yet. Yes it would. In a stable release, either the feature is supported, or it's not. It's not "supported but not guaranteed work", unless that's a bug. Indeed, here, it's a bug that has been fixed in 4.4.1.
  15. The code above invokes undefined behaviour.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!