Replies: 2 comments 4 replies
|
Hey @jmafc, that's an interesting observation! Cpp2's design often prioritizes locality and avoiding global namespace pollution, so restricting to block scope might be a deliberate choice to encourage more explicit declarations or to simplify the parsing of file-level dependencies. It definitely keeps the global scope cleaner, though I can see how it adds a bit of boilerplate for common types like . Curious to hear @hsutter's take on whether this is a permanent constraint or just a current implementation limit! |
|
I just haven't had a use case for implementing it yet. Note that Cpp2 aims to be order-independent, so writing it at non-local scope would be the same as writing it at the top of the file, and so supporting it would have to consider its possible effect on included header files. |
Uh oh!
There was an error while loading. Please reload this page.
It appears that the
usingkeyword is only allowed at function or block scope, but not at file or global scope. For example, you can declareusing std::println;after the opening brace of a function and then useprintln()multiple times within that function. However, if you have a file with several functions each possibly manipulating string instances, you cannot (in pure-cpp2) declareusing std::string;at file scope. If you do, you get an errorpure-cpp2 switch disables Cpp1 syntax, which is not exactly the case, if you can use it within a function.Was there any particular rationale for disallowing
usingat file scope?All reactions