generic-programming

What do you feel is over-generalization?

橙三吉。 提交于 2020-01-23 04:42:26
问题 Having spent some time playing around in Haskell and other functional languages, I've come to appreciate the simplicity of design that comes from describing problems in general terms. While many aspects of template programming can be far from simple, some uses are common enough that I don't think they're an impediment to clarity (especially function templates). I find templates can often simplify the current design while automatically adding a bit of future-resistance. Why should their

How to implement Generic Kafka Streams Deserializer

扶醉桌前 提交于 2020-01-15 03:23:46
问题 I like Kafka, but hate having to write lots of serializers/deserializers, so I tried to create a GenericDeserializer<T> that could deserialize a generic type T. Here's my attempt: class GenericDeserializer< T > implements Deserializer< T > { static final ObjectMapper objectMapper = new ObjectMapper(); @Override public void configure(Map<String, ?> configs, boolean isKey) { } @Override public T deserialize( String topic, byte[] data) { T result = null; try { result = ( T )( objectMapper

Parameter induction with std::variant

ⅰ亾dé卋堺 提交于 2020-01-15 03:15:09
问题 Recenty I am working on an ORM which accepts registration of functions by doing the following: orm->register_func("NAME", &User::set_name); So basically when the database returns the column NAME , the ORM will use the function set_name in User . During the development I learned more about std::variant and here is a little example of how I use it: template<typename RET, typename T, typename ...Args> using FPTR = RET(T::*)(Args...); template<typename T> using VARIANT_FPTR = std::variant<FPTR

Automated Lua Binding using C++

不羁的心 提交于 2020-01-14 18:51:56
问题 I'm building a simple 2D game engine, and its getting bigger and bigger, exposing all of the function in Lua will be impossible: so I'm trying to automate a little bit the process, Is there anyway to get all the n arguments (with different types) from the stack at once and inject them directly into the C++ function. I already automated functions args checking. still the function binding which is a little bit tricky For E.g: I have normal code for changing sprite position: int LuaSprite:

Automated Lua Binding using C++

£可爱£侵袭症+ 提交于 2020-01-14 18:51:29
问题 I'm building a simple 2D game engine, and its getting bigger and bigger, exposing all of the function in Lua will be impossible: so I'm trying to automate a little bit the process, Is there anyway to get all the n arguments (with different types) from the stack at once and inject them directly into the C++ function. I already automated functions args checking. still the function binding which is a little bit tricky For E.g: I have normal code for changing sprite position: int LuaSprite:

Generically overloading operator new while considering alignment requirements

徘徊边缘 提交于 2020-01-14 03:23:07
问题 Situation I am writing a memory manager for dynamic memory (de)allocations. For a class A to use it when operator new (or delete ) is called, it is sufficient for class A to inherit from a class CustomAllocate , which itself overloads new and delete in a way that uses the memory manager. Problem However, apparently I completely missed out on alignment requirements. Unfortunately, CustomAllocate::new has no information about how a class A inheriting from it should be aligned as the only

How to specific a Java Generic class dynamicly

妖精的绣舞 提交于 2020-01-11 11:58:34
问题 If I specific a method which return a generic class,how can I do than I can specific the type of generic class dynamicly ? for example try { Class c =Class.forName(keytype); Class d= Class.forName(valuetype); KafkaConsumer<c,d> consumerconsumer = new KafkaConsumer<c,d>(PropertiesUtil.getPropsObj(configPath)); return consumer ; } catch (ClassNotFoundException e) { e.printStackTrace(); } } But the code above is not OK. How can I do than I can achieve that? 回答1: Generic syntax is good at compile

Django get class from string

心已入冬 提交于 2020-01-06 11:34:13
问题 I'm looking for a generic way in Python to instantiate class by its name in similar way how it is done in Java without having to explicitly specify the class name in IF..ELIF condition. This is because I have several different models and serializers and want to make them addressable by parameters in the HTTP request. It is to enhance loose coupling and modularity. For example https://www.domain.com/myapp/sampledata.json?model=<modelname> should get the classes <modelname> and <modelname

Working with file streams generically

蓝咒 提交于 2020-01-06 05:23:21
问题 I want to work with file streams generically. That is, i want to 'program to an interface and not the implementation'. Something like this: ios * genericFileIO = new ifstream("src.txt"); getline(genericFileIO, someStringObject);//from the string library; dont want to use C strings genericFileIO = new ofstream("dest.txt"); genericFileIO -> operator<<(someStringObject); Is it possible? I am not great with inheritance. Given the io class hierarchy, how do i implement what i want? 回答1: Do you

Working with file streams generically

谁说胖子不能爱 提交于 2020-01-06 05:22:20
问题 I want to work with file streams generically. That is, i want to 'program to an interface and not the implementation'. Something like this: ios * genericFileIO = new ifstream("src.txt"); getline(genericFileIO, someStringObject);//from the string library; dont want to use C strings genericFileIO = new ofstream("dest.txt"); genericFileIO -> operator<<(someStringObject); Is it possible? I am not great with inheritance. Given the io class hierarchy, how do i implement what i want? 回答1: Do you