Skip to main content

Questions tagged [casting]

Casting is a process where an object type is explicitly converted into another type if the conversion is allowed.

1 vote
1 answer
129 views

safe numeric type converter

I have written a function for casting between built in numeric types. I built it to check if the source value is within the range of the destination value, and to provide a nicely legible error if not....
Diederick C. Niehorster's user avatar
2 votes
1 answer
117 views

Absolute value meta programming

I am implementing a generic absolute value function that handles signed and unsigned integer values correctly over the input type's domain. The std::abs(...) ...
dvnlo's user avatar
  • 153
5 votes
3 answers
526 views

Templatizing a Timer class

I'm making a timer class in C++. This is the overview: ...
Alex CB's user avatar
  • 175
1 vote
1 answer
119 views

Verified downcasting if RTTI is active

In an application that uses heavily polymorphic classes, I have often the need to downcast a pointer or a reference to the correct derived class. They should always be of the correct derived class, ...
Aganju's user avatar
  • 189
3 votes
1 answer
194 views

checked conversion function for C++20

Similar to C++ int_cast<> function for checked casts?, but C++20, and with target type deduced from context. The goal is to implement a runtime check that the value being converted can be ...
Simon Richter's user avatar
0 votes
1 answer
105 views

How to not clutter intended casts with static_cast<>? [closed]

have the following struct with one method: ...
DragonGamer's user avatar
4 votes
2 answers
889 views

Method for create a copy of List<T>

I created a method to return a copy of List<T>, basically I convert the List<T> into an array ...
TimeToCode's user avatar
1 vote
1 answer
191 views

Checking if two shapes collide in TypeScript (double dispatch)

Basically, I'm trying to create a generic way to check if two shapes are colliding. I think this is kind of a "double-dispatch" problem, but I'm unsure if there is a better way to solve it ...
Ryan Peschel's user avatar
2 votes
1 answer
588 views

Safe runtime numeric casts

The rationale behind this code is to implement a runtime-safe number conversions in situations when precision loss is possible, but is not expected. Example: passing a ...
Dmitry's user avatar
  • 121
2 votes
3 answers
307 views

ArrayDowncasters Implementation for Downcasting from System.Array to Array of Specific Type in C#

I am working with System.Array and I am trying to convert System.Array objects to array of specific type (such as ...
JimmyHu's user avatar
  • 7,535
0 votes
1 answer
829 views

Converting from `std::array<std::variant<>>` to `void*` [closed]

I'm doing some work with Vulkan, in this I need to pass a set of values of various types. Currently I'm using std::array<std::variant<>> in my interface,...
Jonathan Woollett-light's user avatar
1 vote
2 answers
8k views

How to make Map<String, Object> expendible(?) safely in java

I am building some statistic counter in Java. Each metric could have flexible depth so the implementation should able to explore the depth when value insert or update. So I implement like below (with ...
Juneyoung Oh's user avatar
3 votes
3 answers
667 views

Returning interfaces in Java without significant casting

I am writing some code that takes and returns interfaces following the patterns in Effective Java Third Edition. I understand the principle - we want to take in interfaces because in many cases we don'...
CL40's user avatar
  • 133
2 votes
1 answer
104 views

Parsing csv tokens as doubles and identifying which threw FormatException

Problem Statement I'm reading each line from a .csv file and parsing each comma-delimited value and casting it to the appropriate type: ...
Minh Tran's user avatar
  • 285
6 votes
1 answer
2k views

Implementation of narrow_cast in C++

To summarize what I've been trying to do, I basically tried to make a safe narrow_cast operator, which casts to the Target type if and only if the value is ...
Famiu's user avatar
  • 378

15 30 50 per page
1
2 3 4 5
7