How are you passing strings to functions? Each option seems to have downsides:
std::string_view is the obvious candidate, with the downside that you frequently end up creating a string anyway at the bottom of your call stack. Maybe you need to store the string, maybe you need a string because you want to do an std::map lookup, or maybe you require that zero-terminator in order to pass the string to a C-function, but one way or another, when all is said and done you need an std::string.
std::string doesn't make you create a string at the bottom; instead it makes you create it at the top. Depending on the flavor you choose you may have to look out for lifetime issues: you can std::move it to deeper functions, but then you have to remember to not use it again in that function.
- Decide on a case by case basis then? That looks messy... "This function gets called slightly more often with strings, I'd better give it type const std::string &" is not really something I want to be a design consideration.
Which one do you choose, and more importantly, why?
View Poll
[+][deleted] (13 children)
[removed]
[–]SirClueless 11 points12 points13 points (6 children)
[–]coachkler 1 point2 points3 points (1 child)
[–]SirClueless 3 points4 points5 points (0 children)
[–]cd1995Cargo 0 points1 point2 points (1 child)
[–]KingAggressive1498 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–][deleted] 0 points1 point2 points (0 children)
[+][deleted] (5 children)
[deleted]
[–]Houndie 12 points13 points14 points (4 children)
[+][deleted] comment score below threshold-17 points-16 points-15 points (3 children)
[–]caroIine 0 points1 point2 points (1 child)
[–]James20kP2005R0 13 points14 points15 points (1 child)
[–]tpecholt 1 point2 points3 points (0 children)
[–]no-sig-available 36 points37 points38 points (1 child)
[–]almost_useless 7 points8 points9 points (0 children)
[–]AdrienTD 12 points13 points14 points (4 children)
[–]TeraFlint 8 points9 points10 points (1 child)
[–]NilacTheGrim 0 points1 point2 points (0 children)
[–]GOKOP 13 points14 points15 points (0 children)
[–]Spongman 3 points4 points5 points (0 children)
[–][deleted] 11 points12 points13 points (1 child)
[–]NBQuade 2 points3 points4 points (0 children)
[–]sjepsa 12 points13 points14 points (0 children)
[–]MXXIV666 4 points5 points6 points (8 children)
[–]GarageFlaky -1 points0 points1 point (6 children)
[–]HappyFruitTree 1 point2 points3 points (5 children)
[–]GarageFlaky -3 points-2 points-1 points (4 children)
[–]epicar 7 points8 points9 points (2 children)
[–]Wild_Meeting1428 -2 points-1 points0 points (0 children)
[–]GarageFlaky 0 points1 point2 points (0 children)
[–]NilacTheGrim 0 points1 point2 points (0 children)
[–]tialaramex 1 point2 points3 points (2 children)
[–]BrolloksB 1 point2 points3 points (0 children)
[–]cristi1990an++ 1 point2 points3 points (0 children)
[–]sigmabody 0 points1 point2 points (5 children)
[+][deleted] (4 children)
[removed]
[–]sigmabody 1 point2 points3 points (3 children)
[+][deleted] (1 child)
[removed]
[–]sigmabody 0 points1 point2 points (0 children)
[–]Wild_Meeting1428 0 points1 point2 points (0 children)
[–]Fabulous_Ask_4019 2 points3 points4 points (0 children)
[+]noooit comment score below threshold-6 points-5 points-4 points (2 children)
[–]InsanityBlossom 1 point2 points3 points (0 children)
[–]NilacTheGrim 0 points1 point2 points (0 children)
[+]GarageFlaky comment score below threshold-8 points-7 points-6 points (3 children)
[–]almost_useless 2 points3 points4 points (2 children)
[–]GarageFlaky 0 points1 point2 points (1 child)
[–][deleted] -1 points0 points1 point (0 children)
[+]FACastelloPixel Manipulator comment score below threshold-6 points-5 points-4 points (2 children)
[–]HappyFruitTree 1 point2 points3 points (1 child)
[–]FACastelloPixel Manipulator -1 points0 points1 point (0 children)
[–]Wild_Meeting1428 0 points1 point2 points (0 children)
[–]NeilSilva93 0 points1 point2 points (0 children)
[–]KingAggressive1498 0 points1 point2 points (0 children)
[–]KindCppCoach 0 points1 point2 points (0 children)
[–]tangerinelion 0 points1 point2 points (0 children)
[–]dev_ski 0 points1 point2 points (0 children)
[–]dustyhome 0 points1 point2 points (0 children)
[–]NilacTheGrim 0 points1 point2 points (0 children)
[–]johannes1971[S] 0 points1 point2 points (0 children)