|
I'm having some issues compiling a unicode string class I wrote in GCC 4.5. It used to work fine, but I recently re-programmed the iterator to work in STL algorithms and everything broke horribly. It works just fine in Visual Studio 2010, but it generates a lot of errors in GCC 4.5. Here is a zip file containing the class (irrUString.h), an extremely simple test program, and a couple headers required for irrUString.h to compile (it was developed to be integrated with the Irrlicht engine, so a couple Irrlicht-specific headers are required.) http://irrlicht.suckerfreegames.com/test/ustring.zip Just compile it like this: g++ main.cpp -std=c++0x Can anyone tell me why it is failing to see the typedefs defined in std::iterator? Do I really have to throw in a typename everywhere I use a typedef'ed name in order to get this thing to work? If anyone could tell me what I am doing wrong, I would much appreciate it.
|
# ¿ Jan 24, 2011 08:26 |
|
|
# ¿ May 17, 2024 18:37 |
|
OddObserver posted:http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18
|
# ¿ Jan 24, 2011 15:02 |
|
Thrawn200 posted:
code:
Next, in your main function, you try to call welcome. Except, you aren't passing a variable into the function. You are passing the name of the class. Furthermore, your logic for your welcome function is wrong. The function assigns a name to the global variable player1. It then returns player1's name and sets player1's name to the returned value. That is redundant and there is no need to do that at all. What you are PROBABLY trying to do is this: code:
Nalin fucked around with this message at 05:27 on Feb 20, 2011 |
# ¿ Feb 20, 2011 05:25 |
|
EDIT: Oh no, beaten! There is no 'elseif' statement. However, you CAN do this: code:
|
# ¿ Feb 22, 2011 21:46 |
|
icantfindaname posted:Is there any easy way to concatenate a character to a string in C? Specifically, take a character out of another string, iterating through with a for loop. I tried strcat but apparently it needs to be a constant char for that to work. The program is supposed to check whether a string is a palindrome. That said, all you are trying to do is check if a string is a palindrome? You shouldn't need to do any concatenation at all. code:
Nalin fucked around with this message at 20:34 on Feb 23, 2011 |
# ¿ Feb 23, 2011 05:34 |
|
Standish posted:Also Nalin, looks like you need a tweak: http://codepad.org/zgM8s6YW
|
# ¿ Feb 23, 2011 20:34 |
|
Manic Mongoose posted:thanks for the help so far. Take this as an example pattern: ....?x?ts Based on the rules you gave, the following will match it: eeeexts eeexts eeets Once you start dealing with optional characters, it gets so much more difficult to design. You will need to try to pattern match against every combination of optional characters in your pattern. That means, you have to run your pattern match using the following patterns: ....xts ...xts ....ts ...ts Testing against a simple pattern without any optional characters is easy. Just use two loops, like so: code:
|
# ¿ Feb 25, 2011 03:27 |
|
nielsm posted:I think the easiest way might be to do a recursive algorithm. EDIT: Working code. Try to implement nielsm's solution first before messing with this: http://pastebin.com/6wEgxkgJ Nalin fucked around with this message at 09:04 on Feb 25, 2011 |
# ¿ Feb 25, 2011 04:19 |
|
nielsm posted:That's bad, you can't use it recursively that way. Manic Mongoose posted:If anybody else wants to try to solve it a different way, it would be interesting to see how you do it.
|
# ¿ Feb 25, 2011 08:01 |
|
nielsm posted:Actually no it doesn't. I just tried building it and it has exactly the problem I described. code:
Nalin fucked around with this message at 09:05 on Feb 25, 2011 |
# ¿ Feb 25, 2011 08:35 |
|
pr0metheus posted:What is a good build system for C/C++ projects? I have been using cmake and love it so far, but there is probably something better out there?
|
# ¿ Apr 18, 2011 07:12 |
|
Super Ninja Fish posted:
|
# ¿ Nov 20, 2011 04:03 |
|
Knyteguy posted:A few more small questions: does __int64 (signed long long) only work on 64-bit systems? Why does it throw an error when I use it on codepad? What's a better alternative?
|
# ¿ Jan 18, 2012 03:19 |
|
That Turkey Story posted:Yeah. The code I posted lets you write:
|
# ¿ Jan 18, 2012 22:41 |
|
UnfurledSails posted:XCode outputs this as: e2; The C++ standard doesn't define a specific way for an implementation to evaluate an expression. It looks like XCode is evaluating it from the left to the right, while g++ is evaluating it from the right to the left. In fact, the compiler may choose to evaluate everything randomly for optimization purposes. Nalin fucked around with this message at 05:57 on May 18, 2012 |
# ¿ May 18, 2012 05:47 |
|
Does anybody know how C++20's iterator concepts work? I've been trying to find information on how to construct a custom iterator for C++20's concepts, but I just haven't been able to find anything online describing the changes. Is it some new style of designing your iterator class, or is it just an enhancement on top of the current method of tagging your iterator_category and providing your standard difference_type, value_type, etc, properties? Or is it just too early to think about this because no STL implementation has bothered with it yet?
|
# ¿ Mar 9, 2021 19:17 |
|
code:
Nalin fucked around with this message at 02:58 on Mar 12, 2021 |
# ¿ Mar 12, 2021 01:59 |
|
Nalin posted:How can I make an isA2 concept that wouldn't make the doStuff function ambiguous for A3? Because no matter how much I search on stuff like SFINAE and whatnot, nobody ever seems to have ever had the question, "How do I check for something NOT existing?" Took me forever but I was finally able to solve it. code:
|
# ¿ Mar 12, 2021 03:29 |
|
Jabor posted:What I don't totally understand (perhaps because something is lost in converting the real situation to a toy example) is why the situation even uses templates and concepts to begin with. Basically, I am using Google mathfu, which does terrible things like this: code:
Google was very nice in providing a vector::FromType/ToType function which helpfully just memcpy's the whole data[] array, because that's a great way to frustrate people trying to debug why everything has exploded. Turns out you can't memcpy a float into an int and make it work.
|
# ¿ Mar 12, 2021 04:27 |
|
ShoulderDaemon posted:I mean, I'm assuming that these things are packed appropriately for this to work correctly, but working with the integer-indexed data seems a lot simpler than trying to deal with overloads and named members. It's at this point where "typedef mathfu::Vector<float, 2> Vector2df;" enters the whole codebase and screws up everything.
|
# ¿ Mar 12, 2021 06:54 |
|
ShoulderDaemon posted:I think I must not be understanding the problem you're encountering, because it works okay for me. You know, you are probably right. I could have sworn I tried it and got an error. Wouldn't it just be my luck to have mistaken the problem and spent way too much time messing around with stupid stuff.
|
# ¿ Mar 12, 2021 09:10 |
|
Nalin posted:You know, you are probably right. I could have sworn I tried it and got an error. Wouldn't it just be my luck to have mistaken the problem and spent way too much time messing around with stupid stuff. It's the next day and I'm refreshed now. I know why I didn't see that method of doing it. I was completely focused on doing: auto vec = convert<Vector2di>(floatvec); It is definitely a lot more simple to do: auto vec = convert<int32_t>(floatvec); Lime posted:So your real question has already been answered but if for some reason in the future you really do need to check for a field not existing, you could do it like: (godbolt link) Awesome, thanks! I eventually figured out a similar thing for a different problem I was having. Well, if anything, flailing around like this is definitely giving me a better understanding of things like SFINAE and concepts.
|
# ¿ Mar 12, 2021 19:54 |
|
Beef posted:With Concepts finally being in a released standard, are we seeing an uptick in the use of C++ template mixins? I've never used mixins before, but at least in my hobby projects I've started to make use of concepts in general. I usually try to filter my template with a requires to reduce arcane compiler errors. Like, just a few days ago I took a template function that converts an enum to a number and threw a "requires std::integral<T>" on it. I've also taken to creating new concepts for templates that operate on class member variables and functions in order to make simpler error messages.
|
# ¿ Mar 23, 2021 19:19 |
|
Vargatron posted:If I malloc() a struct, do I have to enter in the struct size or will C figure that out on it's own based on the struct definition? I'm finishing up on my first semester of C programming and we're covering dynamic memory allocation. You have to put in a size to be allocated. You generally do this with the "sizeof" operator. code:
Nalin fucked around with this message at 20:20 on Apr 9, 2021 |
# ¿ Apr 9, 2021 20:17 |
|
cheetah7071 posted:Thanks, that was exactly what I was looking for, and the messiness involved is probably why I couldn't figure it out on my own You could just get into a habit of using std::function. It is slightly less messy! C++ code:
|
# ¿ Sep 4, 2021 02:36 |
|
I've been smacking my head against C++20 modules for a while now and I just haven't been able to get my code to compile. Is anybody able to explain to me why this tiny solution doesn't compile in Visual Studio 2022? If I can find out why it is failing, I would be one step closer to getting my project to compile. I get the following error: C7621: module partition 'Part' for module unit 'File' was not found. The project: https://drive.google.com/file/d/1-9Rotd3c2qSmr1esoYs-1YTQmCYL1oMk/view?usp=sharing
|
# ¿ Jan 3, 2022 11:00 |
|
Well, I think I've figured it out. Visual Studio 2022 17.0.4 cannot have a module implementation unit of a partition. I'm not sure if this is a limitation of modules or a bug with Visual Studio, but I can work around it by either not using partitions or only using partitions without an implementation unit.
|
# ¿ Jan 4, 2022 18:16 |
|
C++20 introduces consteval, which can force a function to be evaluated at compile-time.code:
EDIT: Some searching shows this C++17 based solution: code:
Nalin fucked around with this message at 07:04 on Jan 15, 2022 |
# ¿ Jan 15, 2022 06:51 |
|
drilldo squirt posted:So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that? If C++ and space delimited and only includes numbers, you could just use an istream to read stuff in. Should reduce supporting code. C++ code:
|
# ¿ Jan 25, 2022 05:09 |
|
Xarn posted:Yeah, I am stuck then. The entry point to this mess looks like MAGIC_MACRO( Derived::method ) and I don't think there is a way to split out "derived" in preprocessor. Would you be able to do something like this when creating your classes? https://godbolt.org/z/4x4aW3Y68 EDIT: Actually, that would break Base. Nalin fucked around with this message at 21:34 on Mar 8, 2022 |
# ¿ Mar 8, 2022 21:21 |
|
Are you sure that C++20 changes anything with std::vector<bool>? I don't see any changes mentioned anywhere.
|
# ¿ Apr 23, 2022 01:05 |
|
baby puzzle posted:I want to do something with dates and times but I don't know where to start. Honestly, std::chrono is not going to help you unless you move to C++20 as all of the important calendar functions you want weren't implemented until then. With C++17, all you can really do is grab time points from your system clock and calculate durations between two times. The calendar functionality is what you need to create time points based on dates. It lets you construct time points based off month/day/year, the second Tuesday of a month, etc, and even has some basic functionality like figuring out what day of the week your time is on. However, it cannot do anything more advanced like finding out what day spring starts. But it could do everything else you need. But again, C++20 required. And sorry, I don't know of any date library that would help you off the top of my head. And sadly cppreference.com doesn't list any either.
|
# ¿ May 30, 2022 19:56 |
|
You could use std::bind if you don't want to use a lambda, but I think the general consensus the last time I looked into this is to just use a lambda. BTW, std::bind would look like this: code:
|
# ¿ Jul 28, 2022 22:26 |
|
I've been playing around with modules in one of my hobby projects. I've ICE'd the compiler on multiple versions so far and even logged an EDG (Intellisense) bug. Your first mistake you'll make is trying to import <stl>; You'll try over and over to make it work but eventually you'll just give up. And lol get hosed if you try to use boost. If you want to try modules, it's probably best to just use MSVC 2022. It's probably the best so far out of all of them. AFAIK, cmake still hasn't figured out how they'll do modules yet.
|
# ¿ Sep 9, 2022 04:53 |
|
cheetah7071 posted:while I am still deeply curious how I managed to get a situation where the linker was complaining about being unable to find a file I wasn't trying to link to, I switched to vcpkg and everything works now so good riddance, I guess Boost will use #pragma comment(lib, ...) when the build system is MSVC (or Borland!) This means that the boost headers that you use will auto-link the appropriate boost library. If your build system doesn't install the libs with the correct file name, or you don't pass in #defines to control the auto-linking, you'll have problems. See also: https://www.boost.org/doc/libs/1_63_0/boost/config/auto_link.hpp Nalin fucked around with this message at 22:28 on Nov 20, 2022 |
# ¿ Nov 20, 2022 10:16 |
|
If you wanna have fun writing up compiler bug reports, just try to use C++20 modules in Visual Studio. I've ICE'ed the compiler a couple times already.
|
# ¿ Dec 8, 2022 03:35 |
|
There are many C++ features that people hem and haw over and like to proclaim that nobody should use them. The person in question is just new to C++ and was concerned if this was one of those features that would make life difficult down the road. I am of the opinion that using "if constexpr" is a LOT more easier than dealing with SFINAE stuff on templates and to go ahead and use it all you want.
|
# ¿ Dec 10, 2022 18:22 |
|
AgentF posted:Question: how come this code compiles and works fine with gcc but not msvc? https://godbolt.org/z/e541rovPn This seems to work. What is weird is that inclusive scan says it takes a "FunctionObject" for "binary_op", of which a function pointer should be valid, but the example uses stuff from <functional>, which are all structs with an operator() override. Using a struct with an operator() override seemed to have worked.
|
# ¿ Dec 18, 2022 17:06 |
|
I would probably start on just the concept of memory. Get some graphing paper, tell them that every box is a byte, and start numbering them. Show how bytes, shorts, ints, longs, etc are stored by blocking out multiple boxes. Show how a simple struct is stored. Then explain that a pointer is just a 32/64 bit integer. Block out an integer in the boxes and write in a number that logically represents the id of a different block on the sheet. Maybe erase the number and change it to show how changing the pointer is changing the box it is pointing to. Then explain that the data type associated with the integer just tells the compiler how to interpret the data it sees at that point. Say that the pointer is a byte, then a short, then an int, and show how it reinterprets what it sees. I think that as long as they can conceptually identify that a pointer is just a normal integer and the compiler interprets it in a special way, it would go a long way to helping them understand some of the most complicated parts of C.
|
# ¿ Apr 19, 2023 17:14 |
|
|
# ¿ May 17, 2024 18:37 |
|
Yeah, I'm not sure if you can rely on floating point math to be identical between Intel/AMD, or even within different CPU generations of the same company.
|
# ¿ Jun 26, 2023 07:58 |