От: | niXman | https://github.com/niXman | |
Дата: | 19.12.13 03:56 | ||
Оценка: |
#include <type_traits>
/***************************************************************************/
// библиотечный код
namespace std {
// форварды, ибо сюда нельзя инклюдить <fstream>
template<typename C, typename T>
class basic_ifstream;
template<typename C, typename T>
class basic_ofstream;
} // ns std
template<template<typename C, typename T> class IO>
struct ios_type;
template<template<typename C, typename T> class IO>
struct ios_type<std::basic_ifstream<C, T>>: std::integral_constant<int, 1> {
};
template<template<typename C, typename T> class IO>
struct ios_type<std::basic_ofstream<C, T>>: std::integral_constant<int, 2> {
};
/***************************************************************************/
// пользовательский код
#include <iostream>
int main() {
std::cout << ios_type<std::ifstream>::value << std::endl;
std::cout << ios_type<std::ofstream>::value << std::endl;
}
$ g++ -std=c++11 templspec.cpp -otemplspec
templspec.cpp:21:37: error: 'C' was not declared in this scope
struct ios_type<std::basic_ifstream<C, T>>: std::integral_constant<int, 1> {
^
templspec.cpp:21:40: error: 'T' was not declared in this scope
struct ios_type<std::basic_ifstream<C, T>>: std::integral_constant<int, 1> {
^
templspec.cpp:21:40: error: template argument 1 is invalid
templspec.cpp:21:40: error: template argument 2 is invalid
templspec.cpp:21:41: error: template argument 1 is invalid
struct ios_type<std::basic_ifstream<C, T>>: std::integral_constant<int, 1> {
^
templspec.cpp:24:37: error: 'C' was not declared in this scope
struct ios_type<std::basic_ofstream<C, T>>: std::integral_constant<int, 2> {
^
templspec.cpp:24:40: error: 'T' was not declared in this scope
struct ios_type<std::basic_ofstream<C, T>>: std::integral_constant<int, 2> {
^
templspec.cpp:24:40: error: template argument 1 is invalid
templspec.cpp:24:40: error: template argument 2 is invalid
templspec.cpp:24:41: error: template argument 1 is invalid
struct ios_type<std::basic_ofstream<C, T>>: std::integral_constant<int, 2> {
^
templspec.cpp: In function 'int main()':
templspec.cpp:34:37: error: type/value mismatch at argument 1 in template parameter list for 'template<template<class C, class T> class IO> struct ios_type'
std::cout << ios_type<std::ifstream>::value << std::endl;
^
templspec.cpp:34:37: error: expected a class template, got 'std::ifstream {aka std::basic_ifstream<char>}'
templspec.cpp:35:37: error: type/value mismatch at argument 1 in template parameter list for 'template<template<class C, class T> class IO> struct ios_type'
std::cout << ios_type<std::ofstream>::value << std::endl;
^
templspec.cpp:35:37: error: expected a class template, got 'std::ofstream {aka std::basic_ofstream<char>}'