Top "Const-correctness" questions

Idiomatic Way to declare C++ Immutable Classes

So I have some pretty extensive functional code where the main data type is immutable structs/classes. The way I …

c++ c++11 functional-programming immutability const-correctness
"const correctness" in C#

The point of const-correctness is to be able to provide a view of an instance that can't be altered or …

c# theory const-correctness
What is the best smart pointer return type for a factory function?

With respect to smart pointers and new C++11/14 features, I am wondering what the best-practice return values and function parameter …

c++ c++11 smart-pointers const-correctness
Const vector of non-const objects

In defining a function in an interface : virtual void ModifyPreComputedCoeffs ( std::vector < IndexCoeffPair_t > & model_ ) = 0; we want …

c++ vector constants const-correctness
Const array pointer to const values

If I create a global array of const values, e.g. const int SOME_LIST[SOME_LIST_SIZE] = {2, 3, 5, 7, 11}; is it …

c++ arrays constants const-correctness
Why am I getting an error converting a ‘float**’ to ‘const float**’?

I have a function that receives float** as an argument, and I tried to change it to take const float**. …

c++ const-correctness
const correctness for structs with pointers

I have a struct which contains some pointers. I want the value of these to be unmodifiable. But simply writing …

c constants const-correctness
binary '[' : no operator found which takes a left-hand operand of type 'const std::map<_Kty,_Ty>'

I don't know where the error is coming from. It seems like I'm passing valid data into the [ ] operator. template &…

c++ templates map const-correctness
What are the use cases for having a function return by const value for non-builtin type?

Recently I have read that it makes sense when returning by value from a function to qualify the return type …

c++ const-correctness
Why is const-correctness specific to C++?

Disclaimer: I am aware that there are two questions about the usefulness of const-correctness, however, none discussed how const-correctness is …

c++ constants const-correctness