Questions tagged [tuple-packing]
7 questions
                    
                    50
                    
            votes
                
                4 answers
            
        Tuple unpacking order changes values assigned
I think the two are identical.
nums = [1, 2, 0]    
nums[nums[0]], nums[0] = nums[0], nums[nums[0]]    
print nums  # [2, 1, 0]
nums = [1, 2, 0]    
nums[0], nums[nums[0]] = nums[nums[0]], nums[0]    
print nums  # [2, 2, 1] 
But the results are…
        
        henry
        
- 563
 - 1
 - 5
 - 11
 
                    22
                    
            votes
                
                4 answers
            
        Packing scala tuple to custom class object
I have a tuple
val tuple = ("Mike", 40)
and a case class
case class Person(name: String, age: Int)
How can I pack my tuple to object of Person class? Are there any ways except this:
new Person(tuple._1, tuple._2)
Maybe somesing like…
        
        Pavel Varchenko
        
- 727
 - 1
 - 11
 - 21
 
                    7
                    
            votes
                
                6 answers
            
        scala coalesces multiple function call parameters into a Tuple -- can this be disabled?
This is a troublesome violation of type safety in my project, so I'm looking for a way to disable it. It seems that if a function takes an AnyRef (or a java.lang.Object), you can call the function with any combination of parameters, and Scala will…
        
        Landon Kuhn
        
- 76,451
 - 45
 - 104
 - 130
 
                    5
                    
            votes
                
                5 answers
            
        Converting a list of lists to a tuple in Python
I have a list of lists (generated with a simple list comprehension):
>>> base_lists = [[a, b] for a in range(1, 3) for b in range(1, 6)]
>>> base_lists
[[1,1],[1,2],[1,3],[1,4],[1,5],[2,1],[2,2],[2,3],[2,4],[2,5]]
I want to turn this entire list…
        
        Sean Vieira
        
- 155,703
 - 32
 - 311
 - 293
 
                    4
                    
            votes
                
                1 answer
            
        How to initialize a tuple with a given class having no copy constructor
I have a requirement where tuple needs to be initialized as follows. How do I create a tuple containing class A's object?
#include 
#include 
using namespace std;
class A{
  int a;
public:
  A(const A&)=delete;
  A(int a):…  
        
        AAA
        
- 348
 - 1
 - 4
 - 19
 
                    0
                    
            votes
                
                1 answer
            
        C++, match custom placeholders with function arguments
I am trying to write the piece of code which will do the following: let's assume we have a call of custom bind function 
auto bind_obj = bind(some_func, _1, "test")  
and after we have 
auto res = bind_obj(42) 
where the function some_func: 
int…
        
        Peter Leontev
        
- 107
 - 1
 - 8
 
                    0
                    
            votes
                
                1 answer
            
        Saving the results of a tuple_cat
I have code that I have taken from another source. The rest of the code works great. I am trying to append to a tuple using the following code:
// Because std::make_tuple can't be passed
// to higher order functions.
constexpr struct MakeTuple
{
   …
        
        Ivan
        
- 7,448
 - 14
 - 69
 - 134