Giter VIP home page Giter VIP logo

Comments (4)

weliveindetail avatar weliveindetail commented on May 14, 2024

In addition to the existing Range-based For Loop example, one for C++17 Structured Bindings may be a good candidate, e.g:

#include <cstdio>
#include <tuple>

auto mypair() {
  return std::make_tuple("hello", 1);
}

int main() {
  auto [c, n] = mypair();
  printf("c=%s, n=%d\n", c, n);
}

This emits:

int main() {
  auto __mypair9 = mypair();
  std::tuple_element<0, std::tuple<const char *, int> >::type&& c = get<0ul>(__mypair9);
  std::tuple_element<1, std::tuple<const char *, int> >::type&& n = get<1ul>(__mypair9);
  
  printf("c=%s, n=%d\n", c, n);
}

from cppinsights.

weliveindetail avatar weliveindetail commented on May 14, 2024
#include <cstdio>
#include <string>
#include <tuple>
#include <vector>

template <typename Tuple_t>
void fillTuples(std::vector<Tuple_t> tuples) {
  tuples.emplace_back("hello", 1);
}

int main() {
  std::vector<std::tuple<std::string, int>> tuples;
  fillTuples(tuples);
    
  for (auto [s, n] : tuples) {
    printf("c=%s, n=%d\n", s.c_str(), n);
  }
}

from cppinsights.

Amomum avatar Amomum commented on May 14, 2024

What about recursive templates?

#include <cstdio>
#include <vector>

template<int n>
struct A
{
  static const auto value = A<n-1>::value+n;
};

template<>
struct A<1>
{
	static const auto value = 1;
};


int main()
{
      printf("c=%c\n", A<5>::value);
}

from cppinsights.

andreasfertig avatar andreasfertig commented on May 14, 2024

Hello,

there is now an examples page. Feel free to open pull request for more examples.

Andreas

from cppinsights.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.