7,000 questions
0
votes
1
answer
451
views
how to use ON_CALL and Matcher in gtest with overloaded mocked nfunctions?
I am mocking a class with two overloaded methods like this:
//required because some versions of gtest messes with extra commas in MOCK_METHOD
typedef std::pair<char*, uint32_t> KeyValueType;
...
2
votes
3
answers
137
views
General approach to overloading several similar functions
I have this pattern in my code:
public:
int start(const uint32_t channel);
int stop(const uint32_t channel);
void set_current_desc(uint32_t channel, uint64_t cdesc);
// ...
private:
...
2
votes
0
answers
101
views
Can I make this template choose the right overloaded function?
I have some C++ code that uses templates to create function wrappers around member functions. Here is a link to code on the compiler explorer, and here is the same code below. It's a simplification of ...
1
vote
2
answers
167
views
How to interleave C++ template parameter packs
I have this c++ template function
template <int N, int B, auto... Args>
void somefunc() {
// do work...
}
, which I can call like this:
somefunc<1, true, 2, false>();
I want to ...
5
votes
1
answer
122
views
C++20 concepts that take function type as parameter: how to express compactly while adhering to DRY
I have a hierarchy of classes for which I want to define a generic-type binary operation. I want to define and employ a concept in order to constrain the overloads. While the code works, the use of ...
1
vote
1
answer
76
views
Why does GLSL assume missing function would return a float?
Consider the simple GLSL ES 1.0 and 3.0 code
int i = f();
When f() is not defined, this produces 2 errors:
ERROR: 0:41: 'f' : no matching overloaded function found
ERROR: 0:41: '=' : cannot convert ...
-3
votes
1
answer
114
views
Sort function doesn't work and compiler throw an error of "vector subscript out of range"?
I wrote a code for a project about a famous mathematical constant called the constant of Krapekar. Every number that has four digits, being at least two of them different from each other, will be ...
1
vote
2
answers
148
views
Method overloads with vararg
When designing a (performant) method with variable parameter length like
<T> void consume(T t1)
<T> void consume(T t1, T t2)
<T> void consume(T t1, T t2, T t3)
and a) another ...
2
votes
1
answer
67
views
Overload static templated member function with normal templated member function with different signatures in C++
I have a class MyClass with two simple templated member functions that have the same name test, but one of them is marked as static and their signatures are different:
#include <array>
#include &...
1
vote
1
answer
63
views
Casted override and overloading, will the java compiler create the necessary bytecode?
Assume the next scenario:
interface FloatObject<V> extends Function<Float, V> {
V apply(Float floatObject);
default FloatObject<Float, V> x_5() {
return aFloatObject -&...
2
votes
4
answers
165
views
Mapping enum class to function overload
Hi there I am facing the following problem: I have a class with many member functions of a certain pattern. Each of these member functions has 3 overloads and these overloads are the same for all ...
0
votes
1
answer
68
views
Reuse inheritance tree of one out of multiple classes in Python
I have 2 classes each implementing a specific behavior and using parent classes.
Now I have a new class that needs to use either behavior but which one can only be determined during/after construction....
2
votes
1
answer
85
views
Template function overloading behavior changes with function declaration order
I have the following C++ code which outputs 12:
#include <iostream>
using namespace std;
template<typename T>
T foo(T val) {
return val;
}
template<typename T>
T bar(T n) {
...
3
votes
1
answer
138
views
Clang and gcc getting stuck over overloaded template function
I have to classes Derived1 and Derived2 derived from an abstract base class Base.
I also have a class Container, that contains a map of unique pointers to objects of the Base class, because I want to ...
1
vote
1
answer
56
views
Smarter way to overload methods?
I have a class called Block that has a Draw method. I want to make a function that draws a group of blocks all at once. Since some groups are Arrays and some are lists, I had to add an overload that ...
-1
votes
1
answer
59
views
Reuse overloaded method in python class with most parameters
I have LCD class which is run by micropython on raspberry pi pico which i initialise like this:
class Lcd:
def __init__(self, width, height, channel, sdaPin, sclPin, contrast):
from time ...
2
votes
1
answer
119
views
Order of c++ template arguments affecting compilation
I just encountered a new compilation error in my code after a visual studio update. I have stripped my code down to what I think is a minimal example. I have two templated functions both called pow - ...
3
votes
1
answer
147
views
C# += operator overloading issues
I'm trying to overload operator += .. of course this's not possible by code but If I have not been fooled by docs once overloaded the + operator the += operator will be implicity overloaded.
public ...
1
vote
1
answer
59
views
TypeScript brainteaser: returning an overloaded function
In TypeScript, I can easily create a function with overloads that returns a different return type depending on the input. E.g.,:
function doSomething(mode: "ReturnPromise"): Promise<any&...
2
votes
1
answer
323
views
How to use overload from the typing package within a higher-order function in Python?
Returning an overloaded function from a higher-order callable does not produce expected results with respect to type hints: namely, the resulting function behaves as if it was unannotated at all.
Here ...
0
votes
1
answer
86
views
Is GCC correct in rejecting overload between ref-qualified and non-ref-qualified member function? [duplicate]
If I understand this correctly, [over.load] doesn't exist in c++23, and so what I read in [over.load]/2.3 should not be true anymore, so this code
struct Foo {
int const& bar() const;
int bar()...
2
votes
6
answers
205
views
C++ function template specialization based on the templated return type
In C++20, instead of doing
size_t count = 42;
std::vector<int> my_vector;
vec.reserve(count);
std::copy_n(std::istream_iterator<T>(std::cin), count, std::back_inserter(vec));
I want to be ...
1
vote
2
answers
47
views
C# reflection: Get static method with multiple generic overloads [duplicate]
How we can get a method such as Tuple.Create that has multiple generic overloads through reflection and use it with our custom generic type arguments?
usecase: the generic type arguments are known ...
0
votes
0
answers
85
views
Is there a way to automatically overload functions with a 1-to-1 input-output type correspondence?
Let's say I have this function
from typing import reveal_type
def func(x: str | list[str]) -> int | list[int]:
"""
Some docstring that should show up.
"""
...
0
votes
1
answer
49
views
Reusing overloaded parameter definitions for functions with different returns
I have two functions which have the same overloading of parameters but return different things. Is there someway I can abstract the overloading definition into a shared definition that I can reference ...
2
votes
3
answers
127
views
Variadic template with type checking in C++
I need to have an interface to the driver that provides a set of send() functions only of the following types:
void send(u8 a);
void send(u8 a, u8 b);
void send(u8 a, u8 b, u8 c);
void send(u8 *a, u32 ...
0
votes
1
answer
50
views
Method overloading: trap known arguments with fallback for unknown arguments
I have a legacy project that has a base class which represents complex objects that are built at runtime. These objects have a state with getter/setter methods for the state properties.
In some cases, ...
11
votes
2
answers
963
views
Why can't I pass std::isfinite<double> as a predicate function?
I'm trying to pass a specific overload of std::isfinite() to a function, but GCC refuses:
0.cpp:9:24: error: no matching function for call to ‘all_of(std::array<double, 2>::const_iterator, std::...
2
votes
0
answers
171
views
compiler finds both std::to_address and cuda::std::to_address
I'm trying to build the Nvidia's Minkowski Engine, so I did the following:
git clone
https://github.com/NVIDIA/MinkowskiEngine.git
cd MinkowskiEngine
python setup.py install
However, I get this ...
1
vote
1
answer
66
views
Overloading Set in Swift
Some background
I am very new to Swift and MacOS and trying to learn the Swift way to do things. This started because I realized that tuples are not hashable so I rolled my own:
struct XY: Hashable
{
...
2
votes
2
answers
70
views
Typescript This overload signature is not compatible with its implementation signature
function overloading
I wrote the 2 interfaces. Also I wrote 3 overloading functions. And I have implementation of functions. And here an error - This overload signature is not compatible with its ...
0
votes
0
answers
38
views
Why does varargs get more preference than Object for null value? [duplicate]
Here are two code snippets for example
class HelloWorld {
public void method(Object a){
System.out.println("object");
}
public void method(int... a){
System....
1
vote
1
answer
71
views
Is the "new" method name reserved?
Coming from this helpful question/answer: Constructor chaining in PowerShell - call other constructors in the same class.
To be consistent with the way you call a constructor (e.g. [car]::new()) and ...
6
votes
3
answers
317
views
Overloading and volatile
How is this expected to work?
struct S {};
void foo(volatile S&);
void foo(S);
int main() {
volatile S v;
foo(v);
}
Compilers disagree on it: MSVC accepts the code, while Clang and GCC ...
0
votes
1
answer
100
views
How can I make a const char array function be preferred before a const char* function when resolving function names?
A string literal when passed to a function will be deduced to be first a const char (&)[] array first, and then if not function is suitable it will decay to a const char*. So I thought that the ...
0
votes
1
answer
50
views
Typescript class doesn't allow static async method overloading
I'm trying to overload the login function so that when i pass in an argument to it the return type gets inferred as LoginResponse and when i don't pass any arguments it gets inferred as void | Error. ...
0
votes
0
answers
39
views
Compiler can't find function declaration from header
Im working on a school project focusing on a few topics from overloading to templates
It's a multifile project with 2 custom classes that contain a vector of the other ones type
Inside of the Race ...
0
votes
0
answers
86
views
C2672 '_Sort_unchecked': no matching overloaded function found GA error finding this error in my class sorting usding #include <algorithm>
The thing I am doing is making a Growable Array class in c++ and am using templates for it and in this implementation I have also a subclass iterator //forward olny and then in the main this line is ...
0
votes
1
answer
57
views
Is it possible to make an inherited function call a derived overloaded function?
Suppose I have 3 classes:
example.h
class Object {
public:
Object();
void pass_self_to_external_class();
};
class ObjectWithExtraMember : public Object {
public:
ObjectWithExtraMember();
...
0
votes
2
answers
134
views
Function overloading depending on compile-time object state
Consider having a simple class, that writes integers to cout depending on its state:
#include <iostream>
class NotAWriter{
public:
NotAWriter& operator<<(const int& arg) {
...
0
votes
0
answers
89
views
Unit testing overloaded python methods
I'm trying to unit-test some overloaded Python methods, in an attempt to increase the overall coverage of my code. Here are the overloaded methods, and the main method that is associated with them:
@...
0
votes
0
answers
90
views
What is wrong with my function overload with 8 different argument combinations?
I am trying to override Pydantic's and SQLModel's Field function.
I have 3 boolean arguments which indicate different combinations:
If is_table_field == True, then return SQLModel's FieldInfo, else ...
0
votes
1
answer
83
views
TypeScript Type Inference of result after narrowing
I'm trying to make TypeScript correctly infer the return type of a function (the result) based on the context in which it was called.
TS correctly infers the result as 'isA' | 'isB' because the input ...
0
votes
1
answer
47
views
display method not compiling in Main JAVA
I can't figure out how to call the display method from shape class to the Main method. This is for an assignment, and we're not supposed to change what's written in Main, so the problem has to come ...
1
vote
1
answer
100
views
Deduce member size from initialization list in constructor (CWG 1591) What's the right way? [duplicate]
I have a class Vec<C> that works as below, and I need to know a way to write the constructor and/or deduction guide such that a braced-enclosed initializer list deduces C as std::array<T,N>...
1
vote
1
answer
127
views
How to overload an exported function in a DLL using Delphi?
I have written a DLL with a bunch of different procedures and functions using Delphi. There is one function within this DLL that I want to overload, but as soon as I do, I get a host of errors on all ...
0
votes
1
answer
69
views
How to overload functions string.byte and string.char to support Unicode UTF-8?
I have custom functions utf8Char (decimal) and utf8Byte(char).
How can I overload the functions string.char(...) and string.byte(s, i, j) in Lua?
Here is an example function what I mean:
local ...
1
vote
1
answer
50
views
How to infer parameter types using function overloading in ts
I want to implement a function that can infer the return type through different parameters.
The type can be inferred normally when calling directly, but when using a function to return parameters, the ...
1
vote
1
answer
82
views
is there a typescript generic that handles T | T[] | "*"
I'm new to generics in typescript, it's confusing
is there a way to make the spread operator ... work in the snippet below
the issue
the line [ key: U, ...rest: Reg[U] ], doesn't work as I expect
the ...
0
votes
1
answer
126
views
Is there a way to have separate template function overloads for pointers and arrays?
First off, I would like to draw special emphasis to the C++20 tag, as I believe this problem is much easier to solve using concepts and the requires statement.
Second, when I say array here, I mean ...