overloading

How to overload/specialize template class function to handle arithmetic types and a container-class

一笑奈何 提交于 2019-12-11 17:42:27
问题 I am trying to create a template class with a memberfunction which can handle arithmetic datatypes (int, char, float ...) and a container-class like Eigen::DenseBase<> or std::vector<> Code to demonstrate my idea: template <typename T>class myClass{ ... void foo(T); ... }; template <typename T> void myClass<T>::foo(T){ //Function for arithmetic Datatypes } //Specialization does not work - What is the correct (best?) approach? template <> void myClass<T>::foo(<Eigen::DenseBase<T>){ //Function

Postgres: How to overload functions having single record type input parameter

假装没事ソ 提交于 2019-12-11 16:56:54
问题 I have a user defined type: create type match_input as ( _values text[], _name text, _norm_fn text, _operator text ); and I use this as the input parameter for a function: get_matches(mi match_input) I want to be able to call the same function, but passing a single text value for _values. So I defined a new type: create type match_input_simple as ( _values text, _name text, _norm_fn text, _operator text ); If I try and overload the function with the following: create or replace function get

Is this an elegant way to overload a static member function that provides the same interface as a non static member function?

本秂侑毒 提交于 2019-12-11 15:59:59
问题 Consider the following non class template that has a template variable and uses template aliasing and auto type deduction. template<typename T> using Type = T; using TypeA = Type<int>; using TypeB = Type<double>; class Foo { private: template<typename T> static Type<T> type_; public: template<typename T> explicit Foo( Type<T> type ) { type_<T> = type; } // non static member template<typename T> auto bar() { return type_<T>; } // static member template<typename T> static auto bar(T _x_ = 0) {

TypeScript function generic can only work for function overload with more than one signatures

随声附和 提交于 2019-12-11 14:52:47
问题 I'm defining an interface with generic function like: export interface IState { send: <I, E>(message: I, callback?: (e: E) => void) => IState; } It works fine for classes with more than one signatures: class Left implements IState { send(m: 'go-on', cb?: (e: never) => void): Left; send(m: 'turn-right', cb?: (e: never) => void): Right; send(m: 'go-on' | 'turn-right', cb?: any) { return m === 'go-on' ? new Left() : new Right(); } } class Right implements IState { send(m: 'go-on', cb?: (e: never

No match for operator= error

扶醉桌前 提交于 2019-12-11 14:27:18
问题 This is a snippet of c++ program. Below are given overloaded operator= sign. In the main method is created stringstream type array and I want to compare the contents of that array. *.cpp file: template class Assessment3<stringstream>; template <class T> Assessment3<T> & Assessment3<T>:: operator=(const Assessment3<T>& refer){ if(this != &refer){ for(int x = 0; x < size; x++){ this->array[x]= refer.array[x]; } } return *this; } Header file: #include <string> using namespace std; #ifndef

Can I overload the {} operators for creating dictionaries?

本小妞迷上赌 提交于 2019-12-11 13:44:11
问题 I am making a derived variant of the dict class such that a dictionary value can be accessed through attribute access syntax (so instead of doing dictionary['foo'] you could do dictionary.foo .) This is what I have so far: class dict(dict): __getattr__ = dict.__getitem__ However, this snippet of my code gives it problems: eventD = {'rrule_end':None} . . . . . . #(some time later) print event.rrule_end This is because the { } operators for dictionary creation have not been overloaded. Is it

methods overriding and overloading

限于喜欢 提交于 2019-12-11 12:49:30
问题 can i overload or override methods just by using different return value ? is virtual matter in thie case ? for example : class A{ virtual int Foo(); // is this scenario possible with/without the keyword virtual } class B : public A { virtual double Foo(); } A* Base = new B(); int i = Base->Foo(); // will this just convert double to int ? and regarding overloading : class A{ virtual int Foo(); virtual float Foo(); // is this possible ? int Goo(); float Goo(); // or maybe this ? } Class B{

Why this method for function overloading in C works?

我的未来我决定 提交于 2019-12-11 12:46:28
问题 I've looked over some ways of doing it in C but i've only found for C99. But i've come across the solution below, taken from Lock Less. The thing is, I don't quite understand how it works and would like know the fundamentals of what is going on there to be able to understand it more clearly. I've fetched the web for a while and found this about __VA_ARGS__ , but that alone wasn't enough unfortunately. I would really appreciate an explanation or some guidance about this matter, any kind of

C++ - How to introduce overload set from variadic number of bases.

空扰寡人 提交于 2019-12-11 11:56:51
问题 The derived class hides the name of an overload set from the base class if the derived class has the same name defined, but we can always introduce that overload set back with using-declaration: template <class BASE> class A : public BASE { public: using BASE::some_method; void some_method(); } But what if I introduce all overload sets from variadic base classes? Would I be able to write something like this? template <class... BASES> class A : public BASES... { public: using BASES::some

Why can't compiler determine template of std::max with literal?

Deadly 提交于 2019-12-11 11:35:16
问题 Neither clang nor gcc, compile this: #include <algorithm> int main() { size_t t = 1; t = std::max(t,0); } giving some error of the flavor: error: no matching function for call to 'max(size_t&,int)' ... note: template argument deduction/substitution failed: If I explicitly provide the template type, it works: #include <algorithm> int main() { size_t t = 1; t = std::max<size_t>(t,0); } It's confusing because neither compiler complains with warnings if I compare size_t to 0 , like it would if I