c++


Template template parameter, interior parameter not fixed


I have a template class called MATRIX that takes a single parameter T. I would like to write a function that takes a MATRIX and returns a T valued output. MATRIX typedefs T as elem_type in its implementation. My initial attempt at doing this was:
template<template<typename> class MATRIX>
class MyClass
{
...
MATRIX<>::elem_type myfun(const MATRIX<>& m1);
}
This results in an error "argument list for template template parameter "MATRIX" is missing", which makes sense looking at it. The problem is that I have no idea what to put there. I could specify float, for example, but I would like this function to work regardless of whether the parameter of MATRIX is float, double, uint_16, or whatever else. Is it possible to do this without specifically enumerating all of the possible parameters for MATRIX?
The easiest way of solving this problem is by having MyClass take a single template parameter, and then explicitly specialize it on MATRIX.
template <typename>
class MyClass;
template <template <typename> class MATRIX, typename T>
class MyClass<MATRIX<T>>
{
// ...
typename MATRIX<T>::elem_type myfun(const MATRIX<T>& m1);
};
live example on wandbox
When you have a template template parameter, it is necessary to provide another template argument which can be used to instantiate the template template parameter.
template<template<typename> class MATRIX, typename ElemenType>
class MyClass
{
}
Then, you can use:
template<template<typename> class MATRIX, typename ElemenType>
class MyClass
{
typename MATRIX<ElementType>::elem_type myfun(const MATRIX<>& m1);
}

Related Links

convert bitset<64> to string every 8 bit
argument of type “int” incompatible with parameter of type “int”
When is the correct time to call restoreState for QHeaderView?
How does it pass lvalue reference to std::forward with CRTP?
Using lower_bound function in loop is giving runtime error?
Problems with rand(), always taking the same random generated number [duplicate]
Reading Credentials file fails with error 32
The mechanism of shared_ptr
C++ specialized function template
Compiler errors with cmath on Mac OS X
Array of fstream in C++
Error: (E107) bind interface to port failed: interface already bound to port: port 'MC8051_ALU().AM.port_27' (sc_in)
Error LINK2019 when I try to make a training for face detection [duplicate]
Quickest way to iterate in a C++ vector
How can I use snmp++ to enable/disable a switch port?
i wan't to use char* in this code instead of string how? [closed]

Categories

HOME
angular
sails.js
https
owasp
windows-installer
chart.js
binary
apigee
stormcrawler
webassembly
cllocationmanager
markup
4d-database
sprite
pyside
polymer-1.0
jquery-animate
oracle-data-integrator
autoload
uppaal
sqlcedatareader
cloudfoundry-uaa
phpexcel-1.8.0
outlook-web-app
sphero-api
lift
oracle-ebs
grunt-string-replace
rethinkdb-python
carplay
getelementsbyclassname
api-manager
exports-loader
ctags
family-tree
canvas-lms
behavior
tiles
sp-executesql
vqmod
swig-template
mechanize
mds
agile-project-management
kendo-datepicker
datepart
rodbc
kdiff3
heapsort
adobe-flash-cs3
delphi-5
angularjs-ng-options
eazfuscator
code-completion
kindle-fire
sqr
nxt-python
editplus
jekyll-extensions
ios-provisioning
bonjour
resharper-7.1
dynamic-html
postfix-operator
system.speech.recognition
asp.net-compiler
pmp
mercurial-subrepos
ejbql
visual-studio-test-runner
getprocaddress
sqa
looper
task-tracking

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile