forgive this post, but if you would like to have b...
# announcements
e
forgive this post, but if you would like to have bitwise operatos, please vote this issue: https://youtrack.jetbrains.com/issue/KT-1440
b
Seeing the example you posted, why you dont consider writing a small class to handle those flags?
Copy code
class IntFlag(var value: Int = 0) {
    fun set(f: FLAGS) { value = value or f.value }
    fun unset(f: FLAGS) { value = value and f.value.inv() }

    fun flagged() = FLAGS.values().filter { (value and it.value) != 0 }
}

enum class FLAGS(val value: Int) {
    FIRST(1), SECOND(2), THIRD(4), FOURTH(8) //Use whatever tags you need
}
v
Is there an issue where I can vote AGAINST the bitwise operators? I come from C++, where it is a norm to pack the code with unreadable shifts and masks. It is not worth it.
b
@voddan Cant you vote down on youtrack? Its only up?
e
because of instantiation
I'd need to create a new instance into every sub-function that is called
loc would explode, and the design would get away from the cpp version
b
I dont know your performance constraints, but if you want to avoid instantiation you could use a singleton
Copy code
object FlagHelper {
    val flag = IntFlag()
    fun apply_flags(init: Int = 0, actions: IntFlag.() -> Unit) = with(flag) {
        flag.value = init
        actions()
        value
    }
}
e
immediate gui for 3d realtime graphic
that'd add too much verbosity
atm I am bringing some code down thanks to import renaming
(importing the whole enum isnt an option for me)
b
Ok