1. Список говнокодов пользователя mittorn

    Всего: 38

  2. Haskell / Говнокод #29225

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
    # This Source Code Form is subject to the terms of the Mozilla Public
    # License, v. 2.0. If a copy of the MPL was not distributed with this
    # file, You can obtain one at http://mozilla.org/MPL/2.0/.
    
    if CONFIG['OS_ARCH'] == 'WINNT':
        DIRS += ['win']
    elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
        DIRS += ['mac']
    elif CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3'):
        DIRS += ['unix']
    else:
        DIRS += ['emacs']

    2 часа пытался понять, почему ctrl+a работает как в терминале...
    Это мёртвый код или пасхалка?

    mittorn, 27 Января 2026

    Комментарии (1)
  3. Си / Говнокод #29197

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    thread_local bool nuke_nanosleep;
    #include <syscall.h>
    #include <sys/mman.h>
    #include <dlfcn.h>
    #ifndef PAGE_SIZE
    #define PAGE_SIZE 4096UL
    #define PAGE_MASK (~(PAGE_SIZE-1))
    #endif
    #define PAGE_ALIGN(addr) ((((size_t)addr)+PAGE_SIZE-1)&PAGE_MASK)
    static int fun_rewrite( void *dst, const void *src, const size_t bytes, void *srcBackup )
    {
    	void *start_page;
    	size_t size_of_page;
    
    	if( !( dst && src && bytes ) )
    	{
    		return -1;
    	}
    
    	// At first, backup original src bytes
    	if( srcBackup )
    	{
    		memcpy( srcBackup, src, bytes );
    	}
    
    	// Calculate page for mprotect
    	start_page = (void*)(PAGE_ALIGN( dst ) - PAGE_SIZE);
    
    	if( (size_t)((char*)dst + bytes) > PAGE_ALIGN( dst ) )
    	{
    		// bytes are located on two pages
    		size_of_page = PAGE_SIZE*2;
    	}
    	else
    	{
    		// bytes are located entirely on one page.
    		size_of_page = PAGE_SIZE;
    	}
    
    	// Call mprotect, so dst memory will be writable
    	if( mprotect( start_page, size_of_page, PROT_READ | PROT_WRITE | PROT_EXEC ) ) // This will succeeded only if dst was allocated by mmap().
    	{
    		return -1;
    	}
    
    	// rewrite function
    	memcpy( dst, src, bytes );
    
    	// just in case
    	if( mprotect( start_page, size_of_page, PROT_READ | PROT_EXEC ) )
    	{
    		return -1;
    	}
    
    	// clear instruction caches
    	__clear_cache( (char*)start_page, (char*)start_page + size_of_page );
    
    	return 0;
    }
    static int my_nanosleep(const struct timespec *req, struct timespec *rem)
    {
    	if(nuke_nanosleep)
    		return 0;
    	return syscall(__NR_nanosleep, req, rem);
    }
    
    static void patch_nanosleep()
    {
    	void *libc = dlopen("libc.so", RTLD_NOW);
    	void *pnanosleep = dlsym(libc, "nanosleep");
    	uint64_t my_nanosleep_addr = (uint64_t)&my_nanosleep;
    #ifdef __aarch64__
    	uint32_t shellcode[] =
    		{
    			0x58000042,
    			0x14000003,
    			(uint32_t)(my_nanosleep_addr & 0xFFFFFFFF),
    			(uint32_t)(my_nanosleep_addr >> 32),
    			0xD61F0040
    			//0xd65f03c0
    		};
    	fun_rewrite(pnanosleep, shellcode, sizeof(shellcode), NULL);
    #elif defined(__x86_64__)
    	uint8_t shellcode[] =
    		{
    		0x48, 0x8b, 0x15, 0x02, 0x00, 0x00, 0x00, 0xff,
    		0xe2,
    		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    		};
    	memcpy(&shellcode[0] + 9, &my_nanosleep_addr, 8);
    
    	fun_rewrite(pnanosleep, shellcode, sizeof(shellcode), NULL);
    #endif
    }
    ...
    nuke_nanosleep = 1;
    xrWaitFrame(session, NULL, &frameState);
    nuke_nanosleep = 0;

    Исправляем принудительно блокирующий по спекам xrWaitFrame без костылей с вызовом в отдельном потоке

    mittorn, 12 Ноября 2025

    Комментарии (0)
  4. Куча / Говнокод #29151

    0

    1. 1
    The stylesheet http://govnokod.ru/media/07be0bfd97ac9918b4a7bacde60881b6.css?files=jquery-ui.css,jip.css,jip/jipCore.css,icons.css,bullets.css,flags.css,langs/javascript.css,langs/python.css,langs/.css,langs/c.css was not loaded because its MIME type, “text/html”, is not “text/css”.

    Кто-то обосрался

    mittorn, 04 Июля 2025

    Комментарии (4)
  5. JavaScript / Говнокод #29150

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Казалось бы, измненений не много
    https://github.com/microsoft/monaco-editor/compare/v0.47.0...v0.48.0-dev-20240319
    Но за ними конечно же кроется это
    https://github.com/microsoft/vscode/compare/1e790d77f81672c49be070e04474901747115651...33cd6f1001b92a912898996be69b6928eda1a682
    Все фронтендеры должны гореть в аду

    Где-то здесь поломали рендер. Где, конечно, неясно, эксепшнов никаких нету, просто рисует какую-то эпилепсию вместо текста, но разумеется этот редахтур пихуют повсюду. Как среди этой кучи что-то найти тоже неясно.
    Это не код, авгивевы конюшни.
    Горите блять в аду

    mittorn, 04 Июля 2025

    Комментарии (4)
  6. C++ / Говнокод #28999

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    template <typename T, typename... Ts>
    struct StructureChain : T, StructureChain<Ts...>
    {
    	StructureChain(const T &t, const Ts&... a) : T(t), StructureChain<Ts...>(a...)
    	{
    		((T*)this)->pNext = (StructureChain<Ts...>*)this;
    	}
    };
    
    template <typename T>
    struct StructureChain<T> : T
    {
    	StructureChain(const T &t) : T(t){}
    };
    
    // Positional arguments? Im my C++?  It's more likely than you think!
    template<typename T>
    struct SetterFunc;
    template<typename T, typename V>
    struct SetterVal
    {
    	const SetterFunc<T> &func;
    	const V &val;
    	SetterVal(const SetterFunc<T> &f, const V &v) : func(f), val(v){}
    };
    template<typename T>
    struct SetterFunc
    {
    	const T &func;
    	SetterFunc(const T &data)
    		: func(data)
    	{}
    	template <typename V>
    	SetterVal<T,V> operator() (const V &v) {return SetterVal(*this,v);}
    	template <typename V>
    	SetterVal<T,V> operator= (const V &v) {return SetterVal(*this,v);}
    };
    
    template <typename T, typename... Ts>
    void FillStructure(T &t, const Ts&... ts)
    {
    	auto filler = [](T &t, const auto &arg){
    		auto T::*ptr = arg.func.func(t);
    		t.*ptr = arg.val;
    	};
    	(filler(t,ts),...);
    }
    // todo: remove extra unused copy
    #define $(k) SetterFunc([](auto a){return &decltype(a)::k;})
    
    template <typename T, typename... Ts>
    T $M(T t, const Ts&... ts)
    {
    	FillStructure(t, ts...);
    	return t;
    }
    // ...
    		VkSubresourceLayout layout = {0};
    		layout.rowPitch = pitch1;
    
    		StructureChain iinfo{
    			$M(VkImageCreateInfo{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO},
    			   $(imageType) = VK_IMAGE_TYPE_2D,
    			   $(format) = p010?VK_FORMAT_R16_UNORM:VK_FORMAT_R8_UNORM,
    			   $(extent) = VkExtent3D{ WIDTH, HEIGHT, 1 },
    			   $(mipLevels) = 1,
    			   $(arrayLayers)= 1,
    			   $(samples) =VK_SAMPLE_COUNT_1_BIT,
    			   $(tiling) = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT,
    			   $(usage) = VK_IMAGE_USAGE_STORAGE_BIT,
    			   $(sharingMode) = VK_SHARING_MODE_EXCLUSIVE
    			   ),
    			$M(VkExternalMemoryImageCreateInfo{VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO},
    			   $(handleTypes) = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
    			   ),
    			$M(VkImageDrmFormatModifierExplicitCreateInfoEXT{VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT},
    			   $(drmFormatModifierPlaneCount) = 1,
    			   $(drmFormatModifier) =  mod,
    			   $(pPlaneLayouts) = &layout
    			)
    		};
    		VK_CHECK_RESULT(vkCreateImage(dev.device, &iinfo, NULL, &texture0.image)); // create image.

    Positional arguments? Im my C++? It's more likely than you think!

    mittorn, 15 Октября 2024

    Комментарии (2)
  7. C++ / Говнокод #28928

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for(int i = 0; i < p.mDict.TblSize; i++)
    		for(auto *node = p.mDict.table[i]; node; node = node->n)
    			for(int j = 0; j < node->v.TblSize; j++)
    				for(int k = 0; k < node->v.table[j].count; k++ )
    					if(node->v.table[j][k].v)
    						Log("Section %s: unused config key %s = %s\n", node->k, node->v.table[j][k].k, node->v.table[j][k].v);

    mittorn, 14 Марта 2024

    Комментарии (2)
  8. Си / Говнокод #28923

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    template <typename Key, typename Value, size_t TblPower = 2>
    struct HashMap {
    	struct Node
    	{
    		Key k;
    		Value v;
    		Node *n;
    
    		Node(const Key &key, const Value &value) :
    			k(key), v(value), n(NULL) {}
    
    		Node(const Key &key) :
    			k(key), v(), n(NULL) {}
    	};
    
    	constexpr static size_t TblSize = 1U << TblPower;
    	Node *table[TblSize] = {nullptr};
    
    	HashMap() {
    	}
    
    	~HashMap() {
    		for(size_t i = 0; i < TblSize; i++)
    		{
    			Node *entry = table[i];
    			while(entry)
    			{
    				Node *prev = entry;
    				entry = entry->n;
    				delete prev;
    			}
    			table[i] = NULL;
    		}
    	}
    
    	size_t HashFunc(const Key &key) const
    	{
    		/// TODO: string hash?
    		// handle hash: handle pointers usually aligned
    		return (((size_t) key) >> 8)  & (TblSize - 1);
    	}
    
    	// just in case: check existance or constant access
    	forceinline Value *GetPtr(const Key &key) const
    	{
    		size_t hashValue = HashFunc(key);
    		Node *entry = table[hashValue];
    		while(likely(entry))
    		{
    			if(entry->k == key)
    				return &entry->v;
    			entry = entry->n;
    		}
    		return nullptr;
    	}
    
    	Value &operator [] (const Key &key)
    	{
    		return GetOrAllocate(key);
    	}
    
    #define HASHFIND(key) \
    		size_t hashValue = HashFunc(key); \
    		Node *prev = NULL; \
    		Node *entry = table[hashValue]; \
    	\
    		while(entry && entry->k != key) \
    		{ \
    			prev = entry; \
    			entry = entry->n; \
    		}
    
    	Node * noinline _Allocate(Key key, size_t hashValue, Node *prev, Node *entry)
    	{
    		entry = new Node(key);
    		if(unlikely(!entry))
    		{
    			static Node error(key);
    			return &error;
    		}
    
    		if(prev == NULL)
    			table[hashValue] = entry;
    		else
    			prev->n = entry;
    		return entry;
    	}
    
    	Value& GetOrAllocate(const Key &key)
    	{
    		HASHFIND(key);
    
    		if(unlikely(!entry))
    			entry = _Allocate(key,hashValue, prev, entry);
    
    		return entry->v;
    	}
    // тут был ещё один метод, но в говнокод не влез
    }

    когда СГОРЕЛО от STL

    mittorn, 04 Марта 2024

    Комментарии (0)
  9. Си / Говнокод #28922

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    struct HashArrayMap {
    
    	struct Node
    	{
    		Key k;
    		Value v;
    
    		Node(const Key &key, const Value &value) :
    			k(key), v(value){}
    		Node(const Key &key) :
    			k(key), v(){}
    	};
    
    	constexpr static size_t TblSize = 1U << TblPower;
    	GrowArray<Node> table[TblSize];
    
    	HashArrayMap() {
    	}
    
    	~HashArrayMap() {
    	}
    
    	size_t HashFunc(const Key &key) const
    	{
    		/// TODO: string hash?
    		// handle hash: handle pointers usually aligned
    		return (((size_t) key) >> 8)  & (TblSize - 1);
    	}
    
    	// just in case: check existance or constant access
    	Value *GetPtr(const Key &key) const
    	{
    		size_t hashValue = HashFunc(key);
    		const GrowArray<Node> &entry = table[hashValue];
    		for(int i = 0; i < entry.count; i++)
    		{
    			if(entry[i].k == key)
    				return &entry[i].v;
    		}
    		return nullptr;
    	}
    
    	Value &operator [] (const Key &key)
    	{
    		return GetOrAllocate(key);
    	}
    
    #define HASHFIND(key) \
    	GrowArray<Node> &entry = table[HashFunc(key)]; \
    	int i; \
    	for(i = 0; i < entry.count; i++) \
    		if( entry[i].k == key ) \
    			break;
    
    	Value& GetOrAllocate(const Key &key)
    	{
    		HASHFIND(key);
    		if(i == entry.count )
    			entry.Add(Node(key));
    
    		return entry[i].v;
    	}
    
    	bool Remove(const Key &key)
    	{
    		HASHFIND(key);
    		if(i != entry.count)
    		{
    			entry.RemoveAt(i);
    			return true;
    		}
    		return false;
    	}
    #undef HASHFIND
    };

    когда СГОРЕЛО от STL

    mittorn, 04 Марта 2024

    Комментарии (0)
  10. Си / Говнокод #28921

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    template<class T>
    struct GrowArray
    {
    	T *mem = nullptr;
    	size_t count = 0;
    	size_t alloc = 0;
    
    	GrowArray(size_t init = 0)
    	{
    		if(init)
    			Grow(init);
    	}
    	~GrowArray()
    	{
    		if(mem)
    			free(mem);
    		mem = nullptr;
    		count = 0;
    		alloc = 0;
    	}
    
    	// non-copyable
    	GrowArray(const GrowArray &) = delete;
    	GrowArray &operator = (const GrowArray &) = delete;
    
    	void noinline Grow(size_t size)
    	{
    		if(!size)
    			size = 32;
    		T *newMem = (T*)(mem? realloc(mem, sizeof(T) * size): malloc(sizeof(T)*size));
    
    		if(!newMem)
    			return;
    
    		alloc = size;
    		mem = newMem;
    	}
    
    	// TODO: insert/append
    	bool Add(const T& newVal)
    	{
    		size_t newIdx = count + 1;
    		if(unlikely(newIdx > alloc))
    			Grow(alloc * 2);
    		if(unlikely(newIdx > alloc))
    			return false;
    		mem[count] = newVal;
    		count = newIdx;
    		return true;
    	}
    
    	// TODO: test
    	bool RemoveAt(size_t idx)
    	{
    		if(idx < count)
    			memmove(&mem[idx], &mem[idx+1], sizeof(T) * (count - idx - 1));
    		if(idx <= count)
    		{
    			count--;
    			return true;
    		}
    		return false;
    	}
    	T& operator[](size_t i) const
    	{
    		return mem[i];
    	}
    };

    mittorn, 04 Марта 2024

    Комментарии (0)
  11. C++ / Говнокод #28326

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    #include <stddef.h>
    #include <stdio.h>
    #include <utility>
    #define PLACEHOLDER char x[0];
    
    #define FORCEINLINE 
    template <typename T, typename... Ts> struct MyTuple : MyTuple<Ts...>
    {
    	FORCEINLINE constexpr MyTuple(T&& t, Ts&&... ts)
    		: value(std::move(t))
    		, MyTuple<Ts...> (std::forward<Ts>(ts)...){}
    	FORCEINLINE explicit MyTuple(const MyTuple<T,Ts...> &other) = default;
    	FORCEINLINE MyTuple(MyTuple<T,Ts...> &&other)
    		: MyTuple<Ts...>(std::forward<MyTuple<Ts...>>(other)),
    		value(std::move(other.value)){}
    
    	FORCEINLINE constexpr int size() const { return 1 + MyTuple<Ts...>::size(); }
    	constexpr static int sz = 1 + MyTuple<Ts...>::sz;
    	FORCEINLINE MyTuple<Ts...> &next(){return *static_cast<MyTuple<Ts...>*>(this);}
    	using tnext = MyTuple<Ts...>;
    	T value;
    	FORCEINLINE ~MyTuple() {}
    	constexpr static bool isitem = false;
    };
    struct MyTupleEmpty
    {
    	PLACEHOLDER
    	FORCEINLINE constexpr int size() const { return 0; }
    	static constexpr int sz = 0;
    	~MyTupleEmpty() {}
    	constexpr static bool isitem = false;
    };
    
    template <typename T> struct MyTuple<T> {
    	FORCEINLINE MyTuple(T&& t) : value(std::move(t)){}
    	FORCEINLINE explicit MyTuple(const MyTuple<T> &other) = default;
    	FORCEINLINE MyTuple(MyTuple<T> &&other): value(std::move(other.value)){}
    
    	FORCEINLINE MyTupleEmpty &next() const{
    		static MyTupleEmpty empty;
    		return empty;
    	}
    	FORCEINLINE constexpr int size() const { return 1; }
    	constexpr static int sz = 1;
    	using tnext =MyTupleEmpty;
    	T value;
    	FORCEINLINE ~MyTuple() {}
    	constexpr static bool isitem = false;
    };
    template <class T>struct unwrap_refwrapper{using type = T;};
    template <class T>struct unwrap_refwrapper<std::reference_wrapper<T>>{using type = T&;};
     template <class T> using unwrap_decay_t = typename unwrap_refwrapper<typename std::decay<T>::type>::type;
    template<typename... Ts>
    static FORCEINLINE MyTuple<unwrap_decay_t<Ts>...> MakeTuple(Ts&&... args)
    {
    	return MyTuple<unwrap_decay_t<Ts>...>(std::forward<Ts>(args)...);
    }
    struct i3{
        auto setProp(auto x, i3 t = *(i3*)0)
        {
            typename decltype(x(*this))::tp c;
            return c;
        }
        using tp = i3;
    };
    
    
    #define s(x,y) setProp([](auto c){struct xxx: decltype(c)::tp{decltype(y) x = y;using tp = xxx;    decltype([] (auto xx, xxx &t = *(xxx*)0)\
        {\
            typename decltype(xx(t))::tp c;\
            return c;\
        }) setProp;auto BeginChildren(){return *this;}} d;return d;})
    
    #define c(...) BeginChildren(),MakeTuple(__VA_ARGS__)
    #define i(...) i3()
    
    
    
    
    void func2()
    {
        auto tp = MakeTuple(
        i(Window)
            .s(width,10)
            .s(height,20)
            .c(
                i(Item),
                i(Item2)
                    .s(property1,10.0f)
    
            )
        );
        printf("%d %d %f\n",tp.value.height,tp.value.width, tp.next().value.next().value.property1);
    }
    
    int main()
    {
        func2();
    }

    qml-like структура в compile time
    Стандартизаторы всё пытались запретить шаблоны в локальных классах, да не вышло - понаоставляли дыр в лямбдах и decltype.
    Если добавить -fpermissive, то gcc сожрёт даже с constexpr

    mittorn, 09 Августа 2022

    Комментарии (19)