Used in a Sentence

non-const

How to use non-const in a sentence. Live example sentences for non-const pulled from indexed public discussions.

Editorial note

Compare that to: Iterator find(T& value) const; This function signature accepts only non-const references (unless T is const).

Examples16
Definitions0
Parts of speech1

Quick take

Compare that to: Iterator find(T& value) const; This function signature accepts only non-const references (unless T is const).

Example sentences

1

Compare that to: Iterator find(T& value) const; This function signature accepts only non-const references (unless T is const).

2

Your reference may be const, but something else might still have a non-const reference and mutate the object.

3

There's plenty of times where both sides are non-const and this trick won't save you when that happens.

4

Nim also allows passing by non-const reference without any indication of such at the call site.

5

Are you calling a member function from a const or from a non-const pointer?

6

If you're writing a library, the API should avoid including container details in function parameters, and const and non-const T should be allowed.

7

You either need to be very strict about creating non-const references to objects, or you need to enforce immutability at the class level.

8

A non-const argument will be implicitly cast to const by the compiler.

9

No later code change can accidentally make the const suddenly non-const.

10

Something being const in C++ never meant that other things can't modify it, and the risk you describe has nothing to do with it being a const reference, as opposed to the non-const kind.

11

If you declared most of the mutable types const (and the use cases for a non-const unique_ptr are few) you can avoid most of these issues.

12

>> Nim also allows passing by non-const reference without any indication of such at the call site.

Quote examples

1

The draft actually said "If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified type, the behavior is undefined.".

2

RVO also makes "returning" values through non-const references not as necessary.

3

Whenever I need to return a non-const reference/pointer to some inner data (which is not often) I name the method "mutableFoo()" to make clear what you're getting.

4

I was hoping that "for (const elem: range)" would be added to mean "for (const auto& elem: range)" because I very often find myself within a non-const method having a non-const container but wanting to iterate with no chance of modifying it.

Frequently asked questions

Short answers drawn from the clearest meanings and examples for this word.

How do you use non-const in a sentence?

Compare that to: Iterator find(T& value) const; This function signature accepts only non-const references (unless T is const).