implicit-conversion Questions
3
Solved
I have a Collection, I'm trying to use the Distinct method to remove duplicates.
public static Collection<MediaInfo> imagePlaylist
imagePlaylist = imagePlaylist.Distinct(new API.MediaInfoCo...
Gwen asked 30/12, 2011 at 5:15
2
Solved
#include <cstdio>
#include <string>
class A {
std::string data;
public:
A() = default;
explicit A (const char* data) : data(data) {}
operator const char* () const;
explicit o...
Zillah asked 8/8 at 15:21
1
Consider:
struct A {};
struct B {
operator A&() volatile;
operator A&() const;
operator A&&();
};
B b;
const A& a = b;
(godbolt link: https://godbolt.org/z/jcYch9jdW)
GCC,...
Crowbar asked 4/6 at 10:56
1
Motivated by this question1, I created the following code:
struct X {
X(int) {}
};
struct Y {
operator X() { return X{1}; }
operator int() { return 1; }
};
int main() {
X x(Y{});
}
Live d...
Fanchan asked 23/8, 2018 at 7:43
3
Solved
In a big project, I have this code, compiling well, but I don't understand why.
std::vector<std::string> foo;
if(foo == 1) // Here is the error, the good code is "if(foo.size() == 1)&quo...
Instrumentality asked 8/2 at 11:52
6
Solved
Is it possible to have the compiler automatically convert my Enum values to strings so I can avoid explicitly calling the ToString method every time. Here's an example of what I'd like to do:
enum...
Biotechnology asked 9/6, 2010 at 23:11
2
Solved
Taken from "Scala with cats" (page 18):
Implicit Conversions
When you create a type class instance constructor using an implicit def, be sure to mark the parameters to the method as impl...
Byler asked 5/12, 2020 at 15:33
7
I'm having a list of different types of values exported from JSON.
class StudentDetailsToMarkAttendance {
int att_on_off_status;
String name;
String reg_number;
int status;
StudentDetailsTo...
Catachresis asked 16/6, 2020 at 4:20
3
Solved
I see the term "lvalue-to-rvalue conversion" used in many places throughout the C++ standard. This kind of conversion is often done implicitly, as far as I can tell.
One unexpected (to me...
Cho asked 31/12, 2013 at 1:52
5
Solved
This post is meant to be used as a FAQ regarding implicit integer promotion in C, particularly implicit promotion caused by the usual arithmetic conversions and/or the integer promotions.
Example 1...
Flagg asked 6/9, 2017 at 10:50
1
Solved
I have a structure that is implicitly convertable to the type that is acceptable by the std::map::insert() function.
I use a structure as-is, but I have compilation error:
no overloaded function c...
Zerk asked 7/6, 2023 at 17:41
1
Solved
I stumbled upon a problem with ambiguous overload for operator<< when using std::views::enumerate with size_t range.
More specifically using this code:
#include <iostream>
#include <...
Mideast asked 21/5, 2023 at 10:29
2
C++11 formalized the notion of a narrowing conversion, and disallowed using one at the top level in list-initialization.
I am wondering whether, given two types T and U, it is possible for it to b...
Agon asked 19/11, 2012 at 10:14
3
Solved
#include <iostream>
#include <string>
struct mystruct{
mystruct(std::string s){
std::cout<<__FUNCTION__ <<" String "<<s;
}
explicit mystruct(bool s)...
Vandiver asked 3/3, 2021 at 7:51
9
Solved
How do I avoid implicit casting on non-constructing functions?
I have a function that takes an integer as a parameter,
but that function will also take characters, bools, and longs.
I believe it do...
Limes asked 13/10, 2012 at 22:19
3
Solved
I'm facing MISRA C 2012 violation that I can't understand. Following is the code:
#define I2C_CCRH_FS ((uint8_t)0x80)
#define I2C_CCRH_DUTY ((uint8_t)0x40)
#define I2C_CCRH_CCR ((uint8_t)0x0F)
ty...
Technique asked 7/6, 2018 at 8:29
1
Solved
I have a scenario where I would like to call sum on a sequence of (Double, Double) tuples.
Ideally I would like to do something like the following:
implicit def toTupleNumeric[T](num: Numeric[T]) =...
Nikaniki asked 15/2, 2023 at 11:14
4
I have two types, T and U, and I want to know whether an implicit cast operator is defined from T to U.
I'm aware of the existence of IsAssignableFrom, and this is not what I'm looking for, as it ...
Boozy asked 15/8, 2015 at 13:28
4
Solved
I'm trying to bind some ta-lib functions and then callback.
Here is the simplified sample code:
#include <functional>
#include <type_traits>
#include <cstdint>
struct DataChunk {...
Snappish asked 13/2, 2023 at 9:13
1
Solved
The following small C++ program involving a call to the template function std::atomic_fetch_add() fails to compile in godbolt for x86-64 clang versions less than 9.0 and gcc versions less than 9.1,...
Kagoshima asked 25/1, 2023 at 20:34
1
Assume we have procedure void f(X2);. Further assume we have types X1 and X2 that do not share an inheritance hierarchy.
We want to call it like this: f(X1{}) and have X1 implicitly convert into X2...
Pantoja asked 26/11, 2022 at 13:48
2
Solved
There is a class:
public class Date
{
private DateTime _dateTime;
public Date(DateTime dateTime)
{
_dateTime = dateTime;
}
public static implicit operator DateTime(Date d)
{
if (d == nul...
Geostrophic asked 7/3, 2014 at 15:47
3
Solved
I just read this from the C++14 standard (my emphasis):
4.9 Floating-integral conversions [conv.fpint]
1 A prvalue of a floating point type can be converted to a prvalue of an integer type. The co...
Palacio asked 31/1, 2018 at 17:58
7
Solved
I am trying to set the textColor of a UITextView by assigning it a value.
Earlier in the program I have
textView.textColor = 0x000000;
but later, when I have
textView.textColor = 0x888888;
...
Loseff asked 16/10, 2013 at 13:48
1
Solved
Let's say I have a template function taking a class object:
template<class T>
void Foo(T obj);
and a class definition as follows:
class Bar
{
public:
Bar(int a, bool b): _a(a), _b(b) {}
pr...
Oina asked 14/8, 2022 at 14:33
1 Next >
© 2022 - 2024 — McMap. All rights reserved.