Click here to Skip to main content
15,888,340 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I'm stunned at how stupid EntityFramework is Pin
Jörgen Andersson21-Mar-21 23:30
professionalJörgen Andersson21-Mar-21 23:30 
GeneralRe: I'm stunned at how stupid EntityFramework is Pin
Marc Clifton22-Mar-21 1:58
mvaMarc Clifton22-Mar-21 1:58 
GeneralRe: I'm stunned at how stupid EntityFramework is Pin
pkfox22-Mar-21 0:05
professionalpkfox22-Mar-21 0:05 
GeneralRe: I'm stunned at how stupid EntityFramework is Pin
Espen Harlinn22-Mar-21 1:41
professionalEspen Harlinn22-Mar-21 1:41 
GeneralRe: I'm stunned at how stupid EntityFramework is Pin
Jacquers22-Mar-21 2:16
Jacquers22-Mar-21 2:16 
GeneralAnd here I thought I was clever. Pin
honey the codewitch21-Mar-21 10:36
mvahoney the codewitch21-Mar-21 10:36 
GeneralRe: And here I thought I was clever. Pin
Greg Utas21-Mar-21 14:12
professionalGreg Utas21-Mar-21 14:12 
GeneralRe: And here I thought I was clever. Pin
honey the codewitch21-Mar-21 14:30
mvahoney the codewitch21-Mar-21 14:30 
Update: I fixed it. Eureka!

C++
template<size_t Count,typename Name, typename ...ChannelTraits>
struct channel_index_by_name_impl;

template<size_t Count,typename Name>
struct channel_index_by_name_impl<Count,Name> {
    static constexpr size_t value=-1;
};

template<size_t Count,typename Name, typename ChannelTrait, typename ...ChannelTraits>
struct channel_index_by_name_impl<Count,Name, ChannelTrait, ChannelTraits...> {
    static constexpr size_t value = is_same<Name, typename ChannelTrait::name_type>::value ? Count : channel_index_by_name_impl<Count+1,Name, ChannelTraits...>::value;            
};


Above is the magic I needed

I still haven't figured it out. It's not catching my specializations that I set up for some reason.

This is my i don't know which iteration now.

C++
#define GFX_CHANNEL_NAME(x) struct x { static inline constexpr const char* value() { return #x; } };
...
template<bool Value>
struct boolean_type {
    constexpr static const bool value = Value;
};
template<typename T, typename U>
struct is_same : boolean_type<false> {};

template<typename T>
struct is_same<T, T> : boolean_type<true> {};

template<typename PixelType,typename Name,size_t Count, bool Match, typename ChannelTrait,typename... ChannelTraits>
struct channel_index_by_name_impl {};
template<typename PixelType,typename Name,size_t Count,  typename ChannelTrait,typename... ChannelTraits>
struct channel_index_by_name_impl<PixelType,Name,Count,false,ChannelTrait,ChannelTraits...> {
    constexpr static const size_t value = Count;
    using next = channel_index_by_name_impl<PixelType,Name,Count+1,is_same<Name,typename PixelType::channel_type_by_index<Count+1>::name_type >::value,ChannelTraits...>;
};
template<typename PixelType,typename Name,size_t Count, typename ChannelTrait,typename... ChannelTraits>
struct channel_index_by_name_impl<PixelType,Name,Count,true,ChannelTrait,ChannelTraits...> {
    constexpr static const size_t value = Count;
};


Here the ChannelTraits parameter pack has channel_traits definitions in it, and each of them has a name_type which is a type alias for one of those #defined "strings" above.

The idea is it keeps instantiating the next one in the series until is_same for the next template's name_type is true.

The problem is it always seems to stop at the first one.
Real programmers use butterflies


modified 21-Mar-21 21:08pm.

GeneralRe: And here I thought I was clever. Pin
Greg Utas22-Mar-21 1:05
professionalGreg Utas22-Mar-21 1:05 
GeneralRe: And here I thought I was clever. Pin
honey the codewitch22-Mar-21 9:18
mvahoney the codewitch22-Mar-21 9:18 
PraiseRe: And here I thought I was clever. Pin
Eddy Vluggen22-Mar-21 13:56
professionalEddy Vluggen22-Mar-21 13:56 
GeneralRe: And here I thought I was clever. Pin
honey the codewitch22-Mar-21 15:49
mvahoney the codewitch22-Mar-21 15:49 
GeneralWe've finally named our hens Pin
honey the codewitch21-Mar-21 10:04
mvahoney the codewitch21-Mar-21 10:04 
GeneralRe: We've finally named our hens Pin
pkfox21-Mar-21 10:18
professionalpkfox21-Mar-21 10:18 
GeneralRe: We've finally named our hens Pin
honey the codewitch21-Mar-21 10:24
mvahoney the codewitch21-Mar-21 10:24 
GeneralRe: We've finally named our hens Pin
Nelek21-Mar-21 10:53
protectorNelek21-Mar-21 10:53 
GeneralRe: We've finally named our hens Pin
honey the codewitch21-Mar-21 12:19
mvahoney the codewitch21-Mar-21 12:19 
GeneralRe: We've finally named our hens Pin
dandy7221-Mar-21 12:48
dandy7221-Mar-21 12:48 
GeneralRe: We've finally named our hens Pin
Nelek21-Mar-21 21:01
protectorNelek21-Mar-21 21:01 
GeneralRe: We've finally named our hens Pin
OriginalGriff21-Mar-21 10:18
mveOriginalGriff21-Mar-21 10:18 
GeneralRe: We've finally named our hens Pin
honey the codewitch21-Mar-21 10:23
mvahoney the codewitch21-Mar-21 10:23 
GeneralRe: We've finally named our hens Pin
OriginalGriff21-Mar-21 10:28
mveOriginalGriff21-Mar-21 10:28 
GeneralOff topic: (ish) Pin
OriginalGriff21-Mar-21 10:30
mveOriginalGriff21-Mar-21 10:30 
GeneralRe: We've finally named our hens Pin
MarkTJohnson22-Mar-21 1:06
professionalMarkTJohnson22-Mar-21 1:06 
GeneralRe: We've finally named our hens Pin
RickZeeland21-Mar-21 10:37
mveRickZeeland21-Mar-21 10:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.