mutable

stl hash_map - modifying key

I have a hash map defined as class KeyType { int key; mutable bool flag; KeyType(int key) : key(key), flag(false) {} void setFlag() const { flag = true; } }; struct KeyType_hasher { size_t operator()(const KeyType& s) const { return static_cast<size_t> key; } }; struct KeyType_equal { size_t operat...

How do I create an F# mutable option type?

I need to create a mutable option<T> type in F#. I've tried writing let x = ref None and subsequently writing x := Some(z) but it doesn't work. Help! ...

Project Euler 7 Scala Problem

I was trying to solve Project Euler problem number 7 using scala 2.8 First solution implemented by me takes ~8 seconds def problem_7:Int = { var num = 17; var primes = new ArrayBuffer[Int](); primes += 2 primes += 3 primes += 5 primes += 7 primes += 11 primes += 13 while (primes.size < 10001){ ...

C++ language some live examples for mutable...

Respected sir , I need some help for mutable keyword it is used in a const function and please any body explain for the live example about the mutable and constant function and also diff. for the volatile member and function please help me in Advance Thank you, ...

What is the appropriate way/pattern to collect information from classes?

To keep things simplified lets say I have an interface RandomProvider interface public interface RandomProvider { double nextRandom(); } And say I have 3 different implementations of this interface, ARandom, BRandom, CRandom. I want to collect some statistics about the implementations: how many times nextRandom() is called sum ...

Should this immutable struct be a mutable class?

I showed this struct to a fellow programmer and they felt that it should be a mutable class. They felt it is inconvenient not to have null references and the ability to alter the object as required. I would really like to know if there are any other reasons to make this a mutable class. [Serializable] public struct PhoneNumber : IEquata...

Mutable class as a child of an immutable class

I want to have immutable Java objects like this (strongly simplyfied): class Immutable { protected String name; public Immutable(String name) { this.name = name; } public String getName() { return name; } } In some cases the object should not only be readable but mutable, so I could add mutabili...

What is the proper way to remove elements from a scala mutable map using a predicate

How to do that without creating any new collections? Is there something better than this? val m = scala.collection.mutable.Map[String, Long]("1" -> 1, "2" -> 2, "3" -> 3, "4" -> 4) m.foreach(t => if (t._2 % 2 == 0) m.remove(t._1)) println(m) P.S. in Scala 2.8 ...

How do I properly implement a property in F#?

Consider my first attempt, a simple type in F# like the following: type Test() = inherit BaseImplementingNotifyPropertyChangedViaOnPropertyChanged() let mutable prop: string = null member this.Prop with public get() = prop and public set value = match value with | _ when value = pr...

Why did Matz choose to make Strings mutable by default in Ruby?

It's the reverse of this question: http://stackoverflow.com/questions/93091/why-cant-strings-be-mutable-in-java-and-net Was this choice made in Ruby only because operations (appends and such) are efficient on mutable strings, or was there some other reason? (If it's only efficiency, that would seem peculiar, since the design of Ruby se...

A python random function acts differently when assigned to a list or called directly...

I have a python function that randomize a dictionary representing a position specific scoring matrix. for example: mat = { 'A' : [ 0.53, 0.66, 0.67, 0.05, 0.01, 0.86, 0.03, 0.97, 0.33, 0.41, 0.26 ] 'C' : [ 0.14, 0.04, 0.13, 0.92, 0.99, 0.04, 0.94, 0.00, 0.07, 0.23, 0.35 ] 'T' : [ 0.25, 0.07, 0.01, 0.01, 0.00, 0.04, ...

How to implement IEquatable<T> when mutable fields are part of the equality - Problem with GetHashCode

Hello! I am using Entity Framework in my application. I implemented with the partial class of an entity the IEquatable<T> interface: Partial Class Address : Implements IEquatable(Of Address) 'Other part generated Public Overloads Function Equals(ByVal other As Address) As Boolean _ Implements System.IEquatable(Of Address).Equa...

Why the "mutable default argument fix" syntax is so ugly, asks python newbie

Now following my series of "python newbie questions" and based on another question. Prerogative Go to http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables and scroll down to "Default Parameter Values". There you can find the following: def bad_append(new_item, a_list=[]): a_list.appe...

Simple python oo issue

Hello, Have a look a this simple example. I don't quite understand why o1 prints "Hello Alex" twice. I would think that because of the default self.a is always reset to the empty list. Could someone explain to me what's the rationale here? Thank you so much. class A(object): def __init__(self, a=[]): self.a = a o =...

How to create pointer-to-mutable-member?

Consider the following code: struct Foo { mutable int m; template<int Foo::* member> void change_member() const { this->*member = 12; // Error: you cannot assign to a variable that is const } void g() const { change_member<&Foo::m>(); } }; Compiler generates an error message. The thing is that th...

Plist array , cannot change dictonaries inside

i have a plist that's at its root an array with dictonaries inside it. i load a plist from my recourses as an NSMutableArray. [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Filters" ofType:@"plist"]] i store it into nsuserdefault because it has to be persistent between startups. [[NSUserDefaults sta...

Add a value to an element in a list of sets

Hello. I'm using python, and I have a list of sets, constructed like this: list = [set([])]*n ...where n is the number of sets I want in the list. I want to add a value to a specific set in the list. Say, the second set. I tried list[1].add(value) But this instead adds the value to each set in the list. This behaviour is pretty non...

Is there a writable iterator in Java?

In C+ one can use iterators for writing to a sequence. Simplest example would be: vector<int> v; for (vector<int>::iterator it = v.begin(); it!=v.end(); ++it) { *it = 42; } I need something more complicated - keep iterator as a class member for a later use. But I don't know how to get this behavior from Java iterators. Are there ...

Converting mutable to immutable map

private[this]object MMMap extends HashMap[A, Set[B]] with MultiMap[A, B] How convert it to immutable? ...

boost::serialization with mutable members

Using boost::serialization, what's the "best" way to serialize an object that contains cached, derived values in mutable members, such that cached members aren't serialized, but on deserialization, they are initialized the their appropriate default. A definition of "best" follows later, but first an example: class Example { public: ...