Questions tagged [narrowing]

A type conversion where the destination type which cannot represent all values in the source type.

167 questions
0
votes
2 answers

Typescript: [Compile Time] Writable (- readable) array/object with "as const" type narrowing

Using const assertion, one can nicely narrow an object/array literal's type to its elements. e.g. const arr = [ [5, "hello"], [5, "bye"], ] as const; type T = typeof arr; // type T = readonly [readonly [5, "hello"], readonly [5,…
Aidin
  • 25,146
  • 8
  • 76
  • 67
0
votes
0 answers

What is the difference bettwen using "()" and "{}" to initialize a variable?

This code test.cc #include int main(){ int a = 10; bool b {a}; bool c (a); std::cout << a << " " << b << " " << std::endl; return 0; } In clang or gcc $clang++…
Haoxin
  • 21
  • 3
0
votes
2 answers

Cast and Fail Compilation if a narrowing conversion is possible

In order to prevent "unexpected issues", with format specifies where types are defined in other modules, I'm looking for a cast operator which will fail to compile on a narrowing conversion: this represents a fundamental type error that needs to be…
user2864740
  • 60,010
  • 15
  • 145
  • 220
0
votes
1 answer

Is there an easier way to work with lists of base types

I have a list of a base class List(Of Person) which contains variables which are sub classes Employee and Manager I want to call SetName on each person in the list but vb.net doesnt pick the narrowest overloaded SetName function. Is there a way to…
R. Binter
  • 221
  • 1
  • 8
0
votes
1 answer

Correct syntax for uniform initialization of temporary of type with space in name like unsigned int

I'm trying to pass x of type T to a function foo which expects unsigned int, and I'm not sure what T is because it's a typedef declared in some other module. Both foo and T are not something I can modify. I want compiler to warn me if narrowing…
qbolec
  • 5,374
  • 2
  • 35
  • 44
0
votes
1 answer

Emacs narrow-by-regex

There are functions like M-x narrow-to-line and M-x narrow-to-page. Which routines can help me achieve functionality of non-existing M-x narrow-by-regex? Thanks.
aartist
  • 3,145
  • 3
  • 33
  • 31
0
votes
2 answers

Overload resolution failed because no accessible 'Show' can be called without a narrowing conversion

I've been having issues regarding this narrowing conversion error Overload resolution failed because no accessible 'Show' can be called without a narrowing conversion: 'Public Shared Function Show(owner As System.Windows.Forms.IWin32Window, text As…
Shoc
  • 11
  • 1
  • 5
0
votes
1 answer

How does multi-byte char '\377777' work?

Clang mentioned this thingy to me when I was trying some various non-std ways to find std::numeric_limits::max() for my allocator::max_size() The expression size seems limited at 4 bytes so it looks pretty much like an impl-defined…
sandthorn
  • 2,770
  • 1
  • 15
  • 59
0
votes
1 answer

Differences in narrowing in C++11 between assignment and initialiser lists

C++11 has given us initialiser lists. I've learned that these do not perform narrowing conversions, which sometimes breaks compilation of existing code, for example when operating on enum values with implicitly int-widened values: enum COMMAND …
deets
  • 6,285
  • 29
  • 28
0
votes
2 answers

Need JQuery or JavaScript to use .contains() with && logic

I am attempting to build a simple narrow by filter using given key word buttons on an otherwise static list of items. The buttons are in an unordered list and when selected get the class ".selected-tag-button" added to them. The items are divs with…
talbotini
  • 3
  • 1
0
votes
2 answers

C# signed and unsigned integers are Narrowing conversion both ways?

As per the MSDN article: https://msdn.microsoft.com/en-us/library/8s682k58%28v=vs.80%29.aspx Explicit conversion is required by some compilers to support narrowing conversions.. Based on the statements made in the above msdn link, is it safe to…
Samurai Jack
  • 329
  • 3
  • 10
0
votes
0 answers

metaquery having same metakey with multiple value

I want to show the records which are having "modelyear between 2003 to 2006 and modelyear between 2007 to 2009 AND price between 1 lakh to 3 lakh and price between 3 lakh to 5 lakh" MEANS records having modelyear between 2003 to 2009 and…
Ranjita
  • 1
  • 2
0
votes
0 answers

C++11 : narrowing

I read the below paragraph in the PDF: http://www.stroustrup.com/what-is-2009.pdf Narrowing Maybe you noticed that I used {} initialization consistently. Maybe, you also thought that I was uglifying code and was overenamored by a novel feature?…
0
votes
1 answer

Primitive data types some questions

I'm studying Java and I have some unclear matters I'll be very glad if anybody could help. First question the approx value of int is : 2.147.483,647 the approx value of long is : 9,223,372,036,854,775,807 This website says: "An integer literal is…
JaVaPG
  • 169
  • 1
  • 4
  • 9
-1
votes
1 answer

Narrowly cast low-order bytes in C++

I tried to cast an int to a uint16_t with the following code: std::cout << static_cast(65537) << std::endl; The output was 1. As far as I've got it, only the high-order bits got cast to the destination type. I'm not sure if this is…
Kaiyakha
  • 1,463
  • 1
  • 6
  • 19
1 2 3
11
12