ヘッダファイル:C++に 'ブロックを使用する'構文を追加すると、どのような問題が発生しますか?このような宣言と
void FooBar(System::Network::Win32::Sockets::Handle handle, System::Network::Win32::Sockets::Error& error /*, more fully-qualified param declarations... */);
は、特定のフレームワークでは一般的です。 この問題を緩和できる宣言を使用すると、ヘッダーファイル であるヘッダーファイルの名前ルックアップ規則に影響するため、ヘッダーファイル で使用することは一般的にコーシャーとはみなされません。プライベート宣言されているクラス内のtypedefは、クラスのネームスペースとそれから派生したクラスのネームスペースである を混乱させます。特別な方法で処理されているJavaやPythonの個々のファイルで
using {
// A 'using' block is a sort of way to fence names in. The only names
// that escape the confines of a using block are names that are not
// aliases for other things, not even for things that don't have names
// of their own. These are things like the declarations for new
// classes, enums, structs, global functions or global variables.
// New, non-alias names will be treated as if they were declared in
// the scope in which the 'using' block appeared.
using namespace ::std;
using ::mynamespace::mytype_t;
namespace mn = ::mynamespace;
using ::mynamespace::myfunc;
class AClass {
public:
AClass(const string &st, mytype_t me) : st_(st), me_(me) {
myfunc(&me_);
}
private:
const string st_; // string will refer to ::std::string
mn::mytype_t me_;
};
// The effects of all typedefs, using declarations, and namespace
// aliases that were introduced at the level of this block go away
// here. typedefs and using declarations inside of nested classes
// or namespace declarations do not go away.
} // end using.
// Legal because AClass is treated as having been declared in this
// scope.
AClass a("Fred", ::mynamespace::mytype_t(5));
// Not legal, alias mn no longer exists.
AClass b("Fred", mn::mytype_t);
// Not legal, the unqualified name myfunc no longer exists.
AClass c("Fred", myfunc(::mynamespace::mytype_t(5));
:ここ
は、提案されたソリューションです。他の名前空間の名前をファイルに挿入するインポート宣言を持つことができます。これらの名前は(まあまさにPythonではなく、ここで説明するにはあまりにも複雑ですが)そのファイル内でしか見えません。私はC++にも同様の構造が必要だと思います。プリプロセッサ、#include
ディレクティブ、および翻訳単位のC++コンセプトの存在により、インポートされた名前の暗黙のスコープが問題になります。だから私は、そのような一時的なエイリアスを明示的にスコープするためのいくつかのメカニズムが必要だと思います。
このアイデアでは、どのような問題が予想されますか?問題がない場合、または問題が非常に小さく修正可能な場合は、標準委員会の提案としてどのように提出するつもりですか?
C++を修正する場合は、 '#include'を廃止して、適切なモジュールシステムを導入してください。 – delnan
@delnan - 私は同意しません。私は、Javaのモジュールシステムが非常に刺激的で、場合によっては多少問題があることを知っています。暗黙のファイルスコープが問題だと思います。私は '#include 'を取り除くのは巨大なプロジェクトだと思うし、それが起こる前に何かが正気に必要だと思う。 – Omnifarious
適切な/良いモジュールシステム>>> shittyモジュールシステム>いくつかの問題を解決するためのプリプロセッサと新しい言語構造。 (また、私は完全に深刻ではない) – delnan