|
The Laplace Demon posted:Explanation and code I really appreciate this. I had gotten close to what you have there but had a slight error remaining. I've changed the array name. I agree, it was confusing as it was a remnant of a different method I'd previously tried. I should have cleaned that up prior to posting. Your explanation really helped me understand the code so thanks a lot. I'm not sure why I couldn't get my head around this.
|
# ? Apr 16, 2014 04:10 |
|
|
# ? Jun 8, 2024 00:53 |
|
The Laplace Demon posted:I'm not sure what you mean by not possible. Templated functions can be partially specialized. You're saying that they can be specialized for specific template arguments, which is true; this feature is called explicit specialization. Partial specialization is something you can do to class templates where the specialization is itself still templated; for example: C++ code:
But you cannot do this to function templates.
|
# ? Apr 16, 2014 04:29 |
|
Scrapez posted:I really appreciate this. I had gotten close to what you have there but had a slight error remaining. I've changed the array name. I agree, it was confusing as it was a remnant of a different method I'd previously tried. I should have cleaned that up prior to posting. I had to refer to somewhere else to get my head straight on it too. Like so many short and sweet algorithms, the details can be tricky.
|
# ? Apr 16, 2014 04:30 |
|
rjmccall posted:You're saying that they can be specialized for specific template arguments, which is true; this feature is called explicit specialization. Partial specialization is something you can do to class templates where the specialization is itself still templated; for example: Oh, gotcha. Clever use of SFINAE (e.g. std::enable_if, etc) can work around this, but it gets extremely ugly and can be frustrating. Depending on the situation, tag dispatching can be a fairly clean way to handle this. I've also resorted to putting the implementation inside a static member function of a partially specialized class. As for why it's not possible... Possibly related to the whole function/template overload bonanza?
|
# ? Apr 16, 2014 04:35 |
|
The Laplace Demon posted:If you're using C++11, you can even check your bounds at compile time so you don't have those pesky out-of-bounds access issues. What does the "and" mean in "n and n-1"? (I did try to search for this but you know, not a great word to be trying to search for)
|
# ? Apr 16, 2014 12:47 |
|
Hammerite posted:What does the "and" mean in "n and n-1"? (I did try to search for this but you know, not a great word to be trying to search for) That is literally a keyword you can use as an alternative to && in C++, that nobody uses. See http://en.cppreference.com/w/cpp/language/operator_alternative. It has the same precedence as && (unless I'm sorely mistaken), unlike other languages (such as Perl) where it has weaker precedence.
|
# ? Apr 16, 2014 13:06 |
|
shrughes posted:That is literally a keyword you can use as an alternative to && in C++, that nobody uses. See http://en.cppreference.com/w/cpp/language/operator_alternative. It has the same precedence as && (unless I'm sorely mistaken), unlike other languages (such as Perl) where it has weaker precedence. Ah, I had no idea that you could do that in C++.
|
# ? Apr 16, 2014 13:22 |
|
rjmccall posted:You're saying that they can be specialized for specific template arguments, which is true; this feature is called explicit specialization. Partial specialization is something you can do to class templates where the specialization is itself still templated; for example: C++ templates: all of the complexity of dependent types, none of the benefits (sans code specialization I guess)
|
# ? Apr 16, 2014 14:19 |
|
OneEightHundred posted:I'm more annoyed by template function partial specialization not being possible, and I'm still not sure why it isn't. Which is acceptable behavior in contexts like accidentally treating a pointer as a reference, where the error can be all "hey dude, here's what you meant to write" - it understands and won't do it, but at least it fixes it for you. But the template ones are like "hey dude, I see what you meant to do, but you can't haha! I don't wanna!"
|
# ? Apr 16, 2014 14:48 |
|
Hammerite posted:Ah, I had no idea that you could do that in C++. To expand, it's an "identifier-like operator". The rest of these lovely "features" are (ignoring new and delete): code:
|
# ? Apr 16, 2014 15:07 |
|
The Laplace Demon posted:To expand, it's an "identifier-like operator". The rest of these lovely "features" are (ignoring new and delete):
|
# ? Apr 16, 2014 15:17 |
|
No, they're alternative names for when your character set doesn't have "&".
|
# ? Apr 16, 2014 15:44 |
|
roomforthetuna posted:Can they be overloaded separately from the regular operators? That could make them A. kind of useful, and B. hilariously confusing. No, they're just alternate spellings, like trigraphs, in case you have a weird character set missing & or { or whatever. e;FB
|
# ? Apr 16, 2014 15:53 |
|
Oh hey I wanted to show some really dumb things you can do with bitand a few days ago but didn't want to post it just for the sake of it. Now we're on the topic... You can do this horrible nonsense because it's literally a find->replace! C++ code:
C++ code:
|
# ? Apr 16, 2014 16:01 |
|
I find it weird there's replacements for the comparison operators, but none for the arithmetic ones. You can't write SomeButts mult butts_p = bitand butts; as far as I know.
|
# ? Apr 16, 2014 16:43 |
|
The Laplace Demon posted:To expand, it's an "identifier-like operator". The rest of these lovely "features" are (ignoring new and delete): I dont know why you say this? They are a lot more readable than the regular symbols.
|
# ? Apr 16, 2014 16:54 |
|
Suspicious Dish posted:I find it weird there's replacements for the comparison operators, but none for the arithmetic ones. You can't write SomeButts mult butts_p = bitand butts; as far as I know. shrughes says that the word alternatives ("and" etc) are for cases where your character set doesn't have the necessary symbol. Unicode Explained (page 37) says that there are legacy character sets that are mostly like ASCII but substitute some symbols for others. It describes as "the invariant subset of ASCII" those characters which are the same even in international variants of ASCII. This set includes +, -, * and / and I suppose maybe it was therefore felt that adding keywords like "plus" for + would not be necessary since they should always be available? (The "invariant subset of ASCII" also apparently includes &, but on the other hand it does not include |, so perhaps the motivating case was | and & was also given a word alternative for consistency)
|
# ? Apr 16, 2014 16:56 |
|
The arithmetic operators are part of ISO 646, so there's no need for iso646.h to define alternatives for them (and thus they aren't part of C++'s bizarre dance where everything defined in iso646.h is made a keyword and thus available in programs that don't include that header).
|
# ? Apr 16, 2014 16:57 |
|
I define all my constructors as compl ClassName() {...} too
|
# ? Apr 16, 2014 16:58 |
|
Otto Skorzeny posted:The arithmetic operators are part of ISO 646, so there's no need for iso646.h to define alternatives for them (and thus they aren't part of C++'s bizarre dance where everything defined in iso646.h is made a keyword and thus available in programs that don't include that header). This isn't true for Visual Studio from my experience. You have to include iso646.h for the alternatives to work.
|
# ? Apr 16, 2014 16:58 |
|
xgalaxy posted:This isn't true for Visual Studio from my experience. You have to include iso646.h for the alternatives to work. Yes, this is one of the many instances where VC++ deviates from the C++ language spec (though more understandable than the others).
|
# ? Apr 16, 2014 17:01 |
|
Yeah, I was more wondering about !=. ISO646 seems to define both ! and =.
|
# ? Apr 16, 2014 17:08 |
|
Vanadium posted:I define all my constructors as compl ClassName() {...} too That's a destructor, you dope.
|
# ? Apr 16, 2014 17:09 |
|
Suspicious Dish posted:That's a destructor, you dope. It's hard to tell if there's no squiggly line though!
|
# ? Apr 16, 2014 17:13 |
|
The Laplace Demon posted:
|
# ? Apr 16, 2014 17:15 |
|
xgalaxy posted:I dont know why you say this? They are a lot more readable than the regular symbols. Personal preference plus hyperbole. I find them a lot less readable, as do many others it would seem. I personally like my operators to look like operators and my identifiers to look like identifiers.
|
# ? Apr 16, 2014 17:17 |
|
Zopotantor posted:Whoever invented those, and digraphs, will burn in one of the sultrier corners of Hell. If I've read Dante right, fraud and treachery of this sort merit the 8th circle of hell, Malebolge.
|
# ? Apr 16, 2014 17:20 |
|
The Laplace Demon posted:Personal preference plus hyperbole. I find them a lot less readable, as do many others it would seem. I personally like my operators to look like operators and my identifiers to look like identifiers. It seems to be generally accepted among C(++) coders that && and || should be used rather than "and" and "or". But this is only a norm among a specific community. In Python the operators are "and" and "or", and && and || would be syntax errors. But assuming you have an editor that does syntax highlighting, there is no issue with "operators looking like identifiers". (I think that "and" and "or" are inherently more readable than the symbol versions, but I would not use them in writing C++ because they are not the way people generally expect the the language to be written.)
|
# ? Apr 16, 2014 17:23 |
|
Hammerite posted:But assuming you have an editor that does syntax highlighting, there is no issue with "operators looking like identifiers". What editor do you use that highlights the alternative tokens? They're just macros, so either it special-cases things that transitively include iso646.h and handles redefinition properly, or it's expanding macros to find those that work out to single operator tokens. Those both sound like hanging offenses.
|
# ? Apr 16, 2014 18:27 |
|
Well in Visual Studio they are macros and macros are highlighted different than identifiers or operators. In Xcode or other standard compliant IDE's they are treated like regular operators, not macros, and are highlighted as such. This all depends on your syntax highlighting preferences of course. xgalaxy fucked around with this message at 18:40 on Apr 16, 2014 |
# ? Apr 16, 2014 18:35 |
|
Subjunctive posted:What editor do you use that highlights the alternative tokens? They're just macros, so either it special-cases things that transitively include iso646.h and handles redefinition properly, or it's expanding macros to find those that work out to single operator tokens. Those both sound like hanging offenses. In Python they are a core part of the language, and will be highlighted as operators. I was only pointing out that in principle, in a language, barewords can be operators and look the part.
|
# ? Apr 16, 2014 18:39 |
|
xgalaxy posted:In Xcode or other standard compliant IDE's they are treated like regular operators, not macros, and are highlighted as such. Is that the case only if iso646 is included transitively and nothing is redefined? (In the C case; they're part of the language in C++ but not C IIRC.) Edit: Per http://en.wikipedia.org/wiki/C_alternative_tokens#C.2B.2B Wikipedia posted:The abovementioned identifiers are operator keywords in the ISO C++ programming language and do not require the inclusion of a header file. For consistency, the C++98 standard provides the header <ciso646>. However the latter file has no effect, being empty. Notwithstanding some compilers, such as Microsoft Visual C++, do require the header to be included in order to use these identifiers. Hmm. Subjunctive fucked around with this message at 19:00 on Apr 16, 2014 |
# ? Apr 16, 2014 18:57 |
|
Subjunctive posted:What editor do you use that highlights the alternative tokens? They're just macros, so either it special-cases things that transitively include iso646.h and handles redefinition properly, or it's expanding macros to find those that work out to single operator tokens. Those both sound like hanging offenses. Or it could just have them in the syntax highlighter's hardcoded list of things to highlight and just accept that it'll sometimes highlight things it shouldn't. Syntax highlighters getting edge cases wrong is not at all unusual or a big deal.
|
# ? Apr 16, 2014 19:41 |
|
Plorkyeran posted:Or it could just have them in the syntax highlighter's hardcoded list of things to highlight and just accept that it'll sometimes highlight things it shouldn't. Syntax highlighters getting edge cases wrong is not at all unusual or a big deal. Yeah, and I guess it can tell identifier from operator most of the time based on context anyway. This bothers me more than it should, I'll do some breathing exercises.
|
# ? Apr 16, 2014 20:00 |
|
Subjunctive posted:Is that the case only if iso646 is included transitively and nothing is redefined? (In the C case; they're part of the language in C++ but not C IIRC.) If you pass /Za to MSVC, you can use these operators without requiring the header. However adding /Za results in compiler extensions being disabled. it's also pretty buggy and isn't being actively tested. It hasn't been deprecated either.
|
# ? Apr 16, 2014 20:21 |
|
Suspicious Dish posted:Yeah, I was more wondering about !=. ISO646 seems to define both ! and =.
|
# ? Apr 17, 2014 00:05 |
|
Doesn't the addition of those things potentially break a bunch of backwards-compatibility, for any code where someone had a variable named "not" for example?
|
# ? Apr 17, 2014 03:47 |
|
Yes. But if you have a variable named "not", you deserve to get your code broken.
|
# ? Apr 17, 2014 03:47 |
|
Suspicious Dish posted:Yes. But if you have a variable named "not", you deserve to get your code broken.
|
# ? Apr 17, 2014 05:08 |
|
|
# ? Jun 8, 2024 00:53 |
|
roomforthetuna posted:Maybe, but "or" seems pretty reasonable as a local variable name. Two letter acronym-variables with a small scope are fairly common. My statement still holds.
|
# ? Apr 17, 2014 05:55 |