14 questions
Score of 10
3 answers
5480 views
When and why should I use std::monostate instead of std::optional with an std::variant?
Let's say I am writing a class that passes a std::variant<A,B> to another class.
While I design the class, I decide I'd like to keep a copy of the last thing that was passed to that other class. ...
Score of 1
0 answers
685 views
How to initilize a variant type class member to monostate
In the example below, how would I construct the node object for data = monostate ??
class node : public header
{
using value_type = variant<monostate, string, deque<string>>;
...
Score of 0
2 answers
290 views
Is it safe to reinterpret_cast from std::function<void()> * to std::function<std::monostate()> *?
Example:
std::function<std::monostate()> convert(std::function<void()> func){
return *reinterpret_cast<std::function<std::monostate()> * >(&func);
}
Are std::function&...
Score of 1
1 answer
604 views
every python object of a class has same attribute value after creating [duplicate]
i have two classes BaseNode and BaseEdge which i can use connect method to connect tow nodes via an edge in these classes.
code
here is my BaseNode:
class BaseNode:
def __init__(self,edges=[],value=...
Score of 3
3 answers
468 views
Class vs Instance Scope in JavaScript
I am evaluating a way of use the Singleton Pattern called Monostate in JavaScript.
I have some code like the following:
class Boss {
get name() { return Boss._name }
set name(value) {
Boss....
Score of 13
1 answer
6931 views
What should I use instead of void as one of the alternative types in an variant?
I want to have a variant which may contain type Foo, (disjoint) type Bar, or nothing. Well, naturally, I was thinking of using std::variant<Foo, Bar, void> - but this doesn't seem to work. That ...
Score of 0
2 answers
161 views
Is managing resources in destructor for monostate classes/static members a bad idea in C++?
I'm trying to implement monostate class which manages some std::thread. Thread is running until flag become equals to false. After flag changes to false - thread stops. But looks like I have to call ...
Score of 2
2 answers
944 views
How to prevent a C++ compiler from creating any default class member?
I'm designing some classes to access and control the peripherals of a microcontroller (adc, port, usart etc). The device have just a few (in some cases just one) instances of each peripheral, so I ...
Score of 0
1 answer
33 views
AS3 Accessing Monostate instance child is null
I have an instance of Main that I should be able to access anywhere.
If I want to access a variable on level I should be able do:
_root.level.my_value
However .level is showing up null when I call ...
Score of 2
1 answer
163 views
Polymer monostate pattern element not upgraded
I'm having issues with the monostate pattern in Firefox 35, using Polymer 0.5.2. My element looks like this:
<polymer-element name="tracer-globals">
<script>
(function() {
...
Score of 7
1 answer
397 views
Singleton vs. Monostate Pattern in Ruby
Suppose a class needs to load an external library which takes some time to load and thus should be loaded only once. Two natural solutions to this would be to use the singleton pattern or the ...
Score of 5
2 answers
1376 views
Python Deprecation Warnings with Monostate __new__ -- Can someone explain why?
I have a basic Monostate with Python 2.6.
class Borg(object):
__shared_state = {}
def __new__(cls, *args, **kwargs):
self = object.__new__(cls, *args, **kwargs)
self.__dict__ =...
Score of 1
1 answer
303 views
Is this a proper MonoState Design?
I have a Person Class and based on some help I received in this post.
MonoState, Singleton, or Derived Forms: Best approach for CRUD app?
I have a CurrentPerson class around(??) it and I access the ...
Score of 17
5 answers
7936 views
Class with static members vs singleton
Isn’t a class with only static members a kind of singleton design pattern? Is there any disadvantage of having such a class? A detailed explanation would help.