[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


>millions of features
>can't split a string
>>
>>108823040
strtok is a C++ feature.
>>
>>108823049
>strtok
C. you aren't supposed to use it in C++ since it relies on null termination.
>>
>>108823070
Calling C functions is a C++ feature.
>>
std::views::split, but I would rather it be a method of String (I am not spelling it lowercase)
>>
>>108823105
Making it a method of string means that you'd also have to implement a version for string_view. It would also make sense for all other slice-type containers like deque, vector, or std::span etc. to have their split method. So views::split is the most universal splitting method for all kind of objects. Sadly, iterators in C++ are retarded.
>>
>>108823070
>you aren't supposed to use it in C++
Who's going to stop you? What's up with programmers not knowing what they're doing anymore? As soon as you run into something a textbook says to avoid, you give up? It's just data. Not to mention splitting a string has been a solved problem for decades.
>>
>>108823040
std::views::split
/thread
>>
>>108823040
c++ doesn't even have strings in the first place
>>
its about 10 lines of code if you want something that isn't the abomination strtok.
std::vector<std::string> split(const std::string &str, const char delimeter)
{
std::vector<std::string> v;
std::string s;
for (const char c : str)
{
if (c == delimeter)
{
if (!s.empty())
{
v.push_back(std::move(s));
s.clear();
}
}
else
{
s += c;
}
}
if (!s.empty())
v.push_back(std::move(s));
return v;
}
>>
>>108824005
>shits itself on a unicode string
>>
>>108823040
C++ does not strtok and sscanf?
>>
you can also get creative
auto split(const std::string &str, const char delimeter)
{
return [=]() -> std::optional<std::string> {
static auto it = str.begin();
std::string acc;
while (it != str.end())
{
const auto c = *it++;
if (c == delimeter)
{
if (acc.empty())
continue;
break;
}
acc += c;
}
if (acc.empty())
return std::nullopt;
return acc;
};
}
>>
>>108824363
>auto for function definition return type
what the fuck

i fucking hate c++
>>
>>108824435
a lambda does not have an "accessible" type so to speak. you could wrap it in a std::function if you dislike auto.
>>
>>108824455
auto as a function return type just seems stupid because it forces you to read through the function to figure out what it actually returns. I would have assumed any sane language designer would disallow that
>>
>>108823040
Just use the streaming operator? It splits by white space by default.
>>
>>108824503
>it forces you to read through the function to figure out what it actually returns
Your IDE is supposed to inform you of this.
>>
>>108824363
this code is actually wrong, semantically it would appear that each lambda would be considered different "function" but i guess that is not the case. just make sure this function doesn't "own" the string.
auto split(const std::string &str, const char delimeter)
{
return [it = str.begin(), end = str.end(),
d = delimeter]() mutable -> std::optional<std::string> {
std::string acc;
while (it != end)
{
const auto c = *it++;
if (c == d)
{
if (acc.empty())
continue;
break;
}
acc += c;
}
if (acc.empty())
return std::nullopt;
return acc;
};
}
>>
>>108824606
no faggot, the definition/declaration is

you shouldn't need tooling just to fucking understand the return type, are you deranged?
>>
>>108823494
>As soon as you run into something a textbook says to avoid, you give up?
That's actually how serious engineering unfolds you smelly ad hoc indian
>>
>>108823040
then /g/ wonders why people are moving to rust where you can just . split().nth(n).
>>
>>108823494
>As soon as you run into something a textbook says to avoid, you give up? It's just data.
no, you roll your own idiomatic tokenizer using the std::string data structure which has a known length. for every single project.
>>
>>108824005
this is like 100-1000 times slower tho
>>
File: no_strings_attached.jpg (87 KB, 1357x700)
87 KB JPG
>>108823925
>>
>>108824765
chuds btfo
>>
>>108823477
>calling it a container and not a collection
Stepanov and the STL have been a disaster for the C++ language
>>
>>108824819
This is indisputably true.
>>
>>108824666
Check out Richard Hamming's lecture on "Experts."
>>
>>108824819
Also letting the jews in charge of Boost dominate C++, who keep pushing their garbage designs into the standard or influencing design with their shitty C-with-classes APIs
>>
>append inside loop
SLOW
>>
File: gopher.jpg (76 KB, 992x996)
76 KB JPG
>>108824046
>unicode strings
>>
>>108824765
please post the output of

std::string s("é");
std::cout << s.length();

and tell me again how it have support for strings
>>
>>108823040
golang mogs cpp (besides pure C)
>>
>>108823040
Use <regex> if you like the features so much.
>>
>>108823477
The entire concept of "member functions" was always retarded from day 1. It solves no practical problems and only creates pointless inconsistencies and annoyances.
>>
>>108823077
It's a feature of nearly every popular language.
>>
>>108824666
>fliying machines are impossible! just give up!
Waste of trips.
>>
>>108824626
>?
template<int i>
auto func() {
if constexpr(i)
return 100;
else
return "lol";
}

How does that make you feel anon?
>>
>>108827488
What in tarnation is this?
>>
>>108823040
String-splitting is an anti-feature. Whenever you reach for string splitting what you actually want instead is a proper parser.
>>
>>108824723
I suspected that C++ will become so complex at some point that zoomers will just flip the table and go their own way. On of course, them being zoomers, chose the gayest way possible.
>>
>>108823070
Plus it mutates your string.
>>
>>108827488
>he *is* deranged
bringing up wack-ass template-related caveats is probably a step too far just because you don't care for verbose declarations (and if anything shows the issues with return type deduction being done at template instantiation)
might as well have used some incomprehensible name lookup gotcha to """prove""" that hungarian notation is useless due to analyzers doing everything for you
no really, who argues like this? hurdur keeping track of memory is fake and gay because valgrind exists
>>
>>108827633
>might as well have used some incomprehensible name lookup gotcha to """prove""" that hungarian notation is useless
It's true though. Hungarian notation is worse than useless.
>>
>>108824626
Why not? It isn't 1998 and C++ has unnameable types anyway.
>>
>>108827488
>>108827495
this is what happens when your entire language consists of hacky backports for newfangled higher-level language features onto an increasingly garbled version of C using what amount to increasingly unreadable macros
>>
>>108824723
Rust devs publicly debate their shit.
C++ committee churns out pure garbage with no pushback.
That alone should be reason enough.
>>
>>108827647
which is something you can argue like a sane human bean, instead of pulling shit that only highlights how cpp is not a so much a language as it is three pidgin dialects in a trenchcoat
i guess that's fitting for SEPPLES SUX thread, but you seemingly had a more specfic point about auto type deductions
>>
>>108824547
what if I don't want to split by whitespace, sukhdeep? what if I want to split by ",", or "屌"?
>>
>>108827695
>three pidgin dialects
it's literally just bubba's box of pissin hot C macros
>>
>>108827713
Then use Rust.
>>
File: nfkd.png (52 KB, 1433x661)
52 KB PNG
>>108826956
explain this then.

I only know one language with proper string support, swift, and it's retarded
>>
>>108827719
Unless you take StackOverflow answers as Gospel, C preprocessor macros are unironically better than templates.
>>
>>108827654
I sure love having to type std::pair<std::chrono::time_point<std::chrono::high_resolution_clock>, std::chrono::time_point<std::chrono::high_resolution_clock>> instead of auto!
>>
>>108827731
Strings in Common Lisp literally just work.
>>
>>108827731
>proper string support, swift,
Sounds baity. At least Rust documents that .len() is bytelen. Unicode is extremely convoluted and I can't believe any language can give a reasonable stdlib length that satisfies everyone. Esp in the face of insane shit like compose diacritics and zwj. Does swift normalize grapheme clusters or some insane shit?
>>
File: eq.png (30 KB, 701x354)
30 KB PNG
>>108827743
CL has no notion of grapheme, only codepoints. Like many languages that 'support unicode', their understanding stop at codepoint sequences, and not (visual) characters.

Even in plain utf-8, there are multiple ways to encode for the exact same characters.

>>108827744
My claim about swift comes from this article:
https://lukeplant.me.uk/blog/posts/breaking-provably-correct-leftpad/

Which on swift doc: https://developer.apple.com/documentation/swift/string#Accessing-String-Elements
is explicitly stated that strings are a collection of graphemes, not codepoints.

I'm no swift expert, but they claim that
let a = "\u{00E9}"      // é
let b = "e\u{301}" // e + combining acute

print(a == b)

Would print true, even though a and b have a different internal representation of grapheme é
>>
>>108827763
Uh, based I guess? Sounds like a real footgun though, but Swift basically looks like a collection of nice-to-have footguns so I shouldn't be shocked.
>>
>>108827633
>hungarian notation is useless
it is. and you have obvious skill issues. looks like you got left behind in c++98 era, gramps.
>>
>>108827738
Why did you ever have to type out that shit in the first place?
>>
>>108827838
>hungarian notation was only relevant when developers had no tools that could instantly parse the variable's type and scope
>hungarian notation SUCKS and here is some UNREADABLE DOGSHIT reliant on edge cases of MAD ISO RULINGS to prove that you CNILES can't possibly parse modern day code without a machine
which of these arguments better suits your point, anonymous-kun?
you'd think somebody capable of imperative programming could follow basic logic, but stupidity knows no creed i suppose
>>
>>108827906
>everything I don't understand is an edge case
>I never used it so it's bad
you don't know what modern C++ looks like these days.
>>
>>108827858
idk, some code like this:
template <typename F>
std::pair<std::chrono::time_point<std::chrono::high_resolution_clock>, std::chrono::time_point<std::chrono::high_resolution_clock>> measure(F&& f)
{
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
f();
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
return std::make_pair(start, end);
}
>>
>>108827974
You did not understand the question at all.
>>
>>108827922
so you need a function template that deduces different return types that can't be expressed in terms of SomeThingLike<T> and thus need adhoc deduction when return
returning lambdas or std::functions i suppose? or some other template soup? at this point you are just showing off how big your programming penis is, but i want to remind you that my actual point was that every word i read only shows how wack "modern C++" is, rather than proving the effectiveness of analysis tools
you penis is very big btw, i am humbled
>>
>>108823040
bro make your own 'String', duuh
>>
>>108827922
No and I don't want to know.
>>
>>108827633
>hungarian notation
I didn't know it had a name. Thanks I hate it. Fuck Windows. The other anon is right.
>>
>>108826226
>jews in charge of Boost
>he doesn't know the nazi allegations
>>
>>108824626
Just mouse over it you fucking retard.
>>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *source = @"Sandnigger";

NSRange range = NSMakeRange(4, 6);
NSString *sand = [source substringToIndex:4]; // "Sand"
NSString *nigger = [source substringWithRange:range]; // "Nigger"
}
return 0;
}
>>
>>108826956
does that method return the number of bytes or the number of glyphs?
>>
>>108828371
grim language
void main()
{
import std.stdio: writeln;
import std.range: split;

"sepples lmao".split.writeln;
}
>>
>>108827488
proving his point and that you don't understand it, because you should be using std::variant here for clarity
>>
>>108823040
Use a language made in this millennium
I don't know why retards fall for the ancient language meme, they suck, everyone knows they suck, no one wants to use them because they suck
>>
>>108827731
>>108827763
>swift
>proper string support
It doesn't you to globally override how the length algorithm works (common lisp does), and thus it does not have proper UTF8 string support. PUAs make grapheme count undecidable. The only language I'm aware of with the ability to actually handle true, complete grapheme counting out of the box is clisp, and only through the convoluted extensible sequences protocol that nobody uses. At least sepples has ICU.

Unicode fucking sucks. Knocking any language for not fully covering all bases is absolutely and fundamentally retarded.
>>
>>108829318
all programming languages suck. you're a midwit chasing shiny things.
sepples absolutely is complete garbage though, and people should stop using it.
>>
>>108829263
get a load of that pseud, lmao
>>
>>108823040
String splitting is actually a bit of a cancer. Once you're in a heavily abstracted language like Python or even something like C# or Java where you control a virtual machine via bytecode. But implementing it in C or C++ or even one of the nutech languages is an ugly mess of allocations and managing offsets. String splitting makes operations easier for the programmer, but it is better avoided.
>>
>>108829413
Yes they all suck but languages without even basic string manipulation in 20xx only exist to waste your time
>>
>>108829514
Only high IQ fact ITT.
>>
>>108829514
views make it pretty nice honestly
and you should still be thinking about allocations and all of that when using those "heavily abstracted languages"
the idea that you don't have to worry about that shit is cope from incompetent non-coders. even competent lisp, haskell and prolog programmers think about that stuff as much as C programmers do.
>>
>>108829806
>the idea that you don't have to worry about that shit is cope from incompetent non-coders. even competent lisp, haskell and prolog programmers think about that stuff as much as C programmers do.
I'm not saying there isn't overhead for string splitting in Python. I'm just saying, if you choose Python then performance probably isn't your main concern. I actually prefer if Python code is dogshit slow but readable with few dependencies. The language was meant as a teaching language, follow the KISS principal and use C if you need performance. So many Python programmers like to forget that you can write modules of your codebase in other languages. C# and Java, well, I've gotten into enough flamewars with those jeets to know there's no winning when you have to use one of those languages.
>>
>>108823040
also
>"language" feature
>look inside
>template programming meta language
>>
>>108823040
Splitting a string is a library thing, not a language thing.
The code can be as simple as:
"red,green,blue"sv / ','

Evaluating to a string view generator to avoid unnecessary allocations.
>>
File: urw.gif (443 KB, 480x238)
443 KB GIF
>>108826956
Noncoder rant discarded.
>>
>>108826956
use boost.text
you fagget
>>
>>108824046
>>shits itself on a unicode string
doubt so, if both args are utf-8 clusters.
valid utf8 sequence does not appear in middle of other valid utf8 sequence

C/C++ has boost text for simple, and ICU for very heavy unicode text operations

op is a fag, confusing "text" with advanced unicode clusters/codepoints and all that, which anyway C/C++ does support, with libraries.

if you don't need to cut strings then the lean base C/C++ without libs does it, otherwise use the lib, simple as
>>
>>108834589
not standard



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.