Path: csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: nemethpeter Newsgroups: comp.std.c++ Subject: Replace templates with type builder objects Date: Tue, 18 Sep 2012 08:24:21 -0700 (PDT) Organization: unknown Lines: 99 Sender: std-cpp-request@vandevoorde.com Approved: stephen.clamage@oracle.com Message-ID: <2e5ebb1e-77d0-4a67-ae10-3cc9d5e7cd6c@googlegroups.com> NNTP-Posting-Host: x/AALdR9g2l4aboFlJ85bfzH0a2cyFRrxEyaKwUj3ZE= Content-Type: text/plain; charset=ISO-8859-1 X-Trace: news.albasani.net lfmSu7en5hzyeC5A997wwugiYGVmwbs1xZEWyMnfxC3tnhgW/Hj0ISpfG/xf46LMVm/GwDGcuIrmrycC3yMvOA== X-Complaints-To: abuse@albasani.net NNTP-Posting-Date: Tue, 18 Sep 2012 15:29:22 +0000 (UTC) X-Mailer: Perl5 Mail::Internet v2.05 X-Submission-Address: std-cpp-submit@vandevoorde.com Cancel-Lock: sha1:p8OaimlzTC7rfVyruF1axbZGB8c= X-Original-Date: Mon, 17 Sep 2012 16:16:14 -0700 (PDT) Xref: csiph.com comp.std.c++:544 Hi! I started to think on the subject. So I want to replace the template instantiation in C++ compiling with "normal functions (means compile time programs that works on compiler parse tree or something similar)", and I don't want to use the declerative syntax. Do you think that with the following idea we can replace the whole template mechanism in C++? Do you think that this way result an easier to understand templating? Do you think that this is a right direction? I asked this question on stackoverflow (http://stackoverflow.com/questions/12448723/is-c-template-mechanism-is-just-a-type-builder-funtion) and somebody said that this is the right place for it. This is just an idea, and I just started to thinking on for 1-2 days, so don't expect too much details now... So here is my proposal for new syntax: // old syntax template struct A { A(); // constructor ~A(); // destructor int foo(int, bool) const; // method bool bar; // member T data; // templated member }; // new syntax #if 0 static() { // classes from here: http://clang.llvm.org/doxygen/classclang_1_1Stmt.html class Stmt { }; class IfStmt : public Stmt { }; } // define class as metaclass metaclass class { string name; // static string declaration body; // declaration ?? vector inherits; // static vector }; class NormalClass1 { }; // a function that returns a class class BuildA(typename T) { class ret; // class object can only declared in class builder ret.name = "A"; ret.inherits += (public NormalClass1, public NormalClass2); ret.body += { (); // [0] constructor ~(); // [1] destructor int (int, bool) const; // [2] unnamed method bool bar; // [3] member T data; // [4] templated member } param test_param1 = (int p_test1); param test_param2 = (long p_test); test_param1.type = char; test_param1.name = "p_test1_renamed"; vector params; params.push_back(test_param1); params.push_back(test_param2); ret.body[constructor].params += params; // add parameters to constructor ret.body[2].name = "foo"; // name the unnamed method return ret; } } #endif int main() { A a; #if 0 // create a new class typedef new BuildA(int) AInt; // or typedef new BuildA(int); // in this case class.name must be an initialized thing #endif } -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]