// 1 filename:cpp2011-14-5-7.cpp // ver 0.1 June.15, 2014 // // 2 original examples and/or notes: // (c) ISO/IEC JTC1 SC22 WG21 N3242, April 12, 2011 // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf // >14 Templates 14.5 Template declarations 14.5.7 Aliase templates // (c) Dr. OGAWA Kiyoshi, kaizen at gifu-u.ac.jp, // // 4 compile errors and/or warnings: // 4.1(c) Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) // Target: x86_64-apple-darwin13.2.0, Thread model: posix // Command/Options: c++ -std=c++11 -stdlib=libc++ -Wall cpp2011-14-5-7.cpp // (c) LLVM 2003-2009 University of Illinois at Urbana-Champaign. // 4.2. g++-4.9 (GCC) 4.9.0 20131229 (experimental) // Copyright (C) 2013 Free Software Foundation, Inc. // This is free software; see the source for copying conditions. // There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // http://gcc.gnu.org/onlinedocs/gcc/Standards.html // Command/Options: g++-4.9 -std=c++11 -Wall cpp2011-14-5-7.cpp // g++-4.9: error: unrecognized command line option '-stdlib=libc++' // Configuration:brew install gcc49 // // 4.3. Visual Studio Express 2013, // (c) Microsoft http://www.visualstudio.com/ // SPEC: // Windows 7, .NET Framework // (c) VMware, Inc. // VMWare fusion 6 // // 5. Hardware: MacBook Pro, //(c) Intel http://ark.intel.com/products/37006/ //Core 2 Duo 2.53GHz, 8GB, 1067MHz DDR3 // // 6. Special Thanks: Upper organizatios and // ITSCJ/IPSJ http://www.itscj.ipsj.or.jp/itscj_english/index.html // Renesas Electronics Corporation.http://www.renesas.com/ // NPO SESSAME project, http://www.sessame.jp/workinggroup/WorkingGroup3/ // Toyo Corporation, http://www.toyo.co.jp/English/ // Japan Standard Association, http://bit.ly/1lzykg1 // NPO TOPPERS project, https://www.toppers.jp/asp-d-download.html // Daido Universcity, http://www.daido-it.ac.jp/gakubugakka/computer/index.html // WITZ Co.Ltd., http://www.witz-inc.co.jp/products/solution/solution.html // SevenWise.co., http://www.7ws.co.jp/index.html // TOYOTA Motor Corporation, http://toyota.jp/ // IT planning Inc., http://www.itpl.co.jp/en/index.html // DENSO Corporation, http://www.globaldenso.com/en/ // Aisin Seiki co. Ltd., http://www.aisin.com/ // Spancion Inc., http://www.spansion.com/ // Yazaki Corporation, http://www.yazaki-group.com/global/ // Pananosic Corporation, http://www.panasonic.net/ // SWEST: Summer Workshop on Embedded System Technologies , http://swest.toppers.jp // CEST: Consortium for Embedded System Technology, http://www.ertl.jp/CEST/ // JUSE: Union of Japanese Scientists and Engineers, http://www.juse.or.jp/e/ // OSC:Open Source Conference, http://www.ospn.jp/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; template struct Alloc { /* ... */ }; template using Vec = vector>; Vec v; // same as vector> v; template void process(Vec& v){ /* ... */ } //error: template void process(vector>& w){ /* ... */ } // error: redefinition templateclass TT> void f(TT); //error: f(v); // error: Vec not deduced template class TT> void g(TT>); g(v); // OK: TT = vector // template struct A; template using B = typename A::U; template struct A { typedef B U; }; B b; // error: instantiation of B uses own type via A::U int main() { // cout << "14 Templates 14.5 Template declarations 14.5.7 Aliase templates" << std::endl; return 0; } // 1 error // 1.1 llvm: c++ -std=c++11 -stdlib=libc++ -Wall cpp2011-14-5-7.cpp In file included from cpp2011-14-5-7.cpp:58: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:38: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ios:216: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__locale:15: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/string:439: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/algorithm:627: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/memory:1405:38: error: no type named 'value_type' in 'Alloc' typedef typename allocator_type::value_type value_type; ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:341:22: note: in instantiation of template class 'std::__1::allocator_traits >' requested here typedef typename __alloc_traits::size_type size_type; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:482:15: note: in instantiation of template class 'std::__1::__vector_base >' requested here : private __vector_base<_Tp, _Allocator> ^ cpp2011-14-5-7.cpp:77:10: note: in instantiation of template class 'std::__1::vector >' requested here Vec v; // same as vector> v; ^ In file included from cpp2011-14-5-7.cpp:70: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:490:30: error: '__alloc_traits' is a protected member of 'std::__1::__vector_base >' typedef typename __base::__alloc_traits __alloc_traits; ^ cpp2011-14-5-7.cpp:77:10: note: in instantiation of template class 'std::__1::vector >' requested here Vec v; // same as vector> v; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:338:54: note: declared protected here typedef allocator_traits __alloc_traits; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:491:30: error: 'reference' is a protected member of 'std::__1::__vector_base >' typedef typename __base::reference reference; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:339:54: note: declared protected here typedef value_type& reference; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:492:30: error: 'const_reference' is a protected member of 'std::__1::__vector_base >' typedef typename __base::const_reference const_reference; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:340:54: note: declared protected here typedef const value_type& const_reference; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:493:30: error: 'size_type' is a protected member of 'std::__1::__vector_base >' typedef typename __base::size_type size_type; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:341:54: note: declared protected here typedef typename __alloc_traits::size_type size_type; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:494:30: error: 'difference_type' is a protected member of 'std::__1::__vector_base >' typedef typename __base::difference_type difference_type; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:342:54: note: declared protected here typedef typename __alloc_traits::difference_type difference_type; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:495:30: error: 'pointer' is a protected member of 'std::__1::__vector_base >' typedef typename __base::pointer pointer; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:343:54: note: declared protected here typedef typename __alloc_traits::pointer pointer; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:496:30: error: 'const_pointer' is a protected member of 'std::__1::__vector_base >' typedef typename __base::const_pointer const_pointer; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:344:54: note: declared protected here typedef typename __alloc_traits::const_pointer const_pointer; ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:502:53: error: no type named 'value_type' in 'Alloc' static_assert((is_same::value), ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ cpp2011-14-5-7.cpp:83:1: error: unknown type name 'g' g(v); // OK: TT = vector ^ cpp2011-14-5-7.cpp:86:20: error: no type named 'U' in 'A' template using B = typename A::U; ^~~~~ cpp2011-14-5-7.cpp:88:9: note: in instantiation of template type alias 'B' requested here typedef B U; ^ >11 errors generated.