2

We all know g++ and MSVC can output both preprocessed C++ code (-E) and optimized assembler code (-S). Yet there are no options to output after templates application. Yet I'd like to have it to use with old compilers (the ones that does not support templates).

So, are there any compiler or translator which can produce code after templates application? C++17 are welcome but not necessary.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
iCpu
  • 57
  • 5
  • 1
    Curious why you want to do that... – Steve Nov 22 '17 at 09:11
  • Asking for off-site resources is strictly off-topic – Passer By Nov 22 '17 at 09:13
  • 2
    *"C++17 are welcome but not necessary."* Your compiler doesn't support template but support C++17 ?! – Jarod42 Nov 22 '17 at 09:15
  • 1
    I'm not sure that "template compilation" is separable from other aspects of compilation, cf. the preprocessor and compiler. Therefore I'm not sure this makes sense. Doesn't make this a bad question though. Have an upvote. – Bathsheba Nov 22 '17 at 09:16
  • Steve, programming old processors may be difficult. – iCpu Nov 22 '17 at 09:32
  • @Bathsheba, I'm sure it is because you can't start optimization without getting full list of classes and their dependencies. Which templates application is. – iCpu Nov 22 '17 at 09:47
  • 1
    If you want to porr modern C++ code to a compiler that doesn't support templates, you are going to encounter more problems than just templates. – n. m. could be an AI Nov 22 '17 at 10:08
  • Templates aren't expanded at the point of use like a macro though, and multiple instantiations on the same parameters are shared across translation units. I'm not sure what this output would actually look like in order to work correctly. – Useless Nov 22 '17 at 10:09
  • 1
    [This](https://stackoverflow.com/a/1833628/775806) might be one way to get what you are trying to do going. YMMV. – n. m. could be an AI Nov 22 '17 at 10:22
  • @Useless, yes they are. Template classes and functions expands into common classes and functions (and constants, thanks c++17). They only get unique names like `_ZTTSt13basic_istreamIwSt11char_traitsIwEE` instead of `std::cin` (or whatever this ugly creature were before) – iCpu Nov 22 '17 at 10:47
  • I meant they weren't expanded _at the point of use_, which is why I said exactly that. Instantiation isn't localised in the same way as macro expansion (at the least it needs the linker to dedupe). – Useless Nov 22 '17 at 10:59

0 Answers0