wrapping enum class for python - pybind11

I am trying to wrap an enum class in a c++ header file for use in a python project.I have googled around and can not find out how to achieve this - is it supported?
enum class scheme-type : std::uint8_t
{
a=10;
b=20;
};
How to convert the above code in python wrapper using pybind11

Related

How does getx realize the `.obs` thing

Learning Flutter/getx package I came across the sample code like the following:
import 'package:get/get.dart';
class MyHomePageController extends GetxController {
final count = 0.obs;
}
The code 0.obs scares me. I mean how an integer can have a .obs attribute? what has the getx pacakge done to my code?
This is a feature of dart language called extension introduced in Dart 2.7, it is a way to add functionality to existing libraries.
You might use extension methods without even knowing it.
For example, when you use code completion in an IDE, it suggests extension methods alongside regular methods.
For example, consider the following code that parses a string into an integer:
int.parse('42')
It might be nice — shorter and easier to use with tools — to have that functionality be on String instead:
'42'.parseInt()
To enable that code, you can import a library that contains an extension of the String class:
import 'string_apis.dart';
// ···
print('42'.parseInt()); // Use an extension method.
Extensions can define not just methods, but also other members such as getter, setters, and operators. Also, extensions have names, which can be helpful if an API conflict arises. Here’s how you might implement the extension method parseInt(), using an extension (named NumberParsing) that operates on strings.
extension NumberParsing on String {
int parseInt() {
return int.parse(this);
}
// ···
}
SUMMARY
the get package use extensions behind the scene to call getter of RxInt.
Object so the attribute is not actually called upon primitive datatype
this is from the source code of the get package ... you can access it by pressing ctrl+ ".obs"
extension IntExtension on int {
/// Returns a `RxInt` with [this] `int` as initial value.
RxInt get obs => RxInt(this);
}

Swift package manager (spm) protocols, are not recognised in the project

I just converted a git repository to Swift Package Manager (spm), all good, it compiles and I can import it in the project.
What is not good is that the project doesn't compile, is not seeing the protocol. My lib is a single generic class and i'm supposed to create an enum that implements the protocol then use the enum as a generic of the class.
enum LocalPreferences: String, RCPreferencesProtocol {
I get: Use of undeclared type RCPreferencesProtocol
Then I get further errors when trying to use the enum but i think this are only because the enum had an error:
private let localPreferences = RCPreferences<LocalPreferences>()
I get: Cannot specialize a non-generic definition
Anybody had this problem and fixed it?
Here is reference to the library is the lib for reference.
I made a stupid mistake, didn't declared the protocol and class public in the package. Strange though that the unit tests of the package passed instead giving the same error.

Extend a type using generics

In Swift, I am trying to create a generic class that can extend another class, while inheriting from it. I am able to do it in C++ as follows, but is there a way to do the same in Swift?
class Atom {};
template<typename Base, typename Extension>
class Extend: Base {
Extension _value;
};
int main() {
return 0;
}
One approach I have been trying to apply is Protocol Oriented Design, but it doesn't seem to be able to take a class and extend it. The best I reached is something like creating the extension manually, and declaring that it does extend Atom, but at that point, I would just create another class and add to it the respective property manually.
One way to do it is by generating the code for the subclass at compile or run time. check these answers of these questions:
How to generate code dynamically with annotations at build time in Java?, and Generating, compiling and using Java code at run time?.
You can add a custom generic method to the base class that would be overridden by each subclass (in the generated code) and it may return Object. It would be a working approach, if it's worth the hassle.

Is it possible to alias an import?

In c# when pulling in a library that has a lot of name collisions with existing code, there's a way to alias the import so you don't need to fully clarify the namespace for each use. eg:
using MyCompany.MyLibrary.Model as MMM
then you could do
MMM.MyObject
instead of
MyCompany.MyLibrary.Model.MyObject
With the recent update to swift 3.0, I've found some of my model objects are now colliding with the Foundation types, and I've been forced to prefix things that used to have an NS prefix in the class name with Foundation.classname. It would be great if I could type alias the import of my model library much like the c# example given above. Is this possible in swift 3.0? If not is there another strategy to avoid name collisions that would result in having to write the framework name in front of each type? I'm considering going back to prefixing my class names like we did in obj-c, but I'm trying to explore my options before I do that.
Update 2021 for Swift 5;
No, but you can import all and alias (in separate file), read below for more details.
Generally
You can import a particular entity as well as the entire module:
import struct­ SomeModule.SomeStruct
import class­ SomeModule.SomeClass
import func SomeModule.someFunc
See the full list of "importable" entity types in the import-kind rule of Swift grammar.
Then you can create a typealias:
typealias SMSomeStruct = SomeModule.SomeStruct
And, as of Swift 3, there is no import declaration combined with aliasing.
Considering the Collisions with Foundation Entities
Say, you have a class SomeModule.NumberFormatter.
It is enough to create two typealiases in a separate Swift file (in an importing project) to prevent collisions:
import Foundation
import SomeModule
typealias NumberFormatter = Foundation.NumberFormatter
typealias SMNumberFormatter = SomeModule.NumberFormatter
It's not even with Swift 5 possible to directly alias an import-statement!?
But fortunately, I could workaround it with something like:
import typealias MyModule.MyInnerClass
I mean, if we are the module's developer, simply move the alias into the module, like:
public typealias MyInnerClass = MyClass.MyInnerClass
public class MyClass {
public class MyInnerClass {
// Some cool logic here...
}
}

Is putting your class inside a struct an acceptable way to namespace your class in Swift?

Is putting your class inside a struct an acceptable way to namespace your class in Swift? I did not see any mention of nested struct or struct-class in the programming guide.
struct TestNamespace {
class Test {
}
}
I'd be (even more) happy with namespaces in Swift, because they help organize the code more granularly. If you're experimenting with using struct as a namespace, consider disabling its construction:
struct PseudoNamespace {
private init() {}
//...
}
Using struct has an advantage over using class: structs does not support inheritance and with classes it needs using final modifier.
One significant disadvantage of this emulation is that there is no way no "import" such a namespace (like import PseudoNamespace.*, etc.), because Swift allows importing modules, but not structs.