Question: I'm declaring my std::map and use it below:

```
    map<int, int, function<bool (int, int)>> m;
    m.insert(make_pair(12,3));
    m.insert(make_pair(3,4));
    for(auto & p : m){
        cout << p.first << "," << p.second << endl;
    }

```

g++ compiles, no error.
Template parameter only requires a type, but no function body is required, passes compilation. I was wondering how this empty comparer would behave. On running it:

```
terminate called after throwing an instance of 'std::bad_function_call'
  what():  bad_function_call

```

I only see this error in calling pure virtual function. But my code is using stl template, no polymorphism is in place.

So is this a c++ design issue, that compilation doesn't check if a function only has declaration but no function body to run? Plus, how would c++ standard deal with this?

Appreciate your explanations.

Answer: 
Just in `didSelectItemAt` write a switch case.

```
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    if collectionView == firstCV {
        handleCases(text : firstData[indexPath.item])
    } else {
        handleCases(text : secondData[indexPath.item])
    }

}

func handleCases(text : String) {
    switch text {
        case firstData[0]:
            print("clicked \(firstData[0])
            // write here code to go to details
            break

        case firstData[1]:
            print("clicked \(firstData[0])
            break

        // put all 6 cases of firstData and secondData and then default
    }
}

```

---

Another solution will be add IBAction inside cell and call `handleCases(text : String)` inside cell in this IBAction.
I found out it's better to use @IBAction callback function for the two button's instead of delegate callback function aka(didSelect)

first you can create @IBAction in (TwoCollectionsViewController) then link both (buttonOne, buttonTwo) to this func, in the mean time while user pressed a button you can know which button was pressed(depends on your use case), for that setting an id for the buttons is best option,
you can add this line to both Collection view button(buttonOne, buttonTwo) before returning the cell in(cellForRowAt):
cell.buttonOne.restorationIdentifier = "(indexPath.row)"

then add:

```
if let btn = sender as? UIButton {
   print(btn.restorationIdentifier)
}

```

to the @IBAction func, after that you can use:

```
performSegue(withIdentifier: "Your Identifier", sender: btn)

```

override: `prepare(for segue: UIStoryboardSegue, sender: Any?)` function
then you can configure destination View Controller in the (prepare function)

hopefully this solves your issue :)

update:  

first change the

```
cell.buttonTwo.restorationIdentifier = "\(indexPath.row)"

```

inside second if statement (if collectionView == secondCV) to

```
cell.buttonTwo.restorationIdentifier = "\(indexPath.row + firstData.count)"

```

then change @IBAction to:

```
@IBAction func buttonPressed(_ sender: Any) {
 guard let button = sender as? UIButton else { return }
 guard let id = Int(button.restorationIdentifier!) else {return} 
 if id < firstData.count { 
  performSegue(withIdentifier: "Good Work", sender: btn) 
 } 
 else { 
  performSegue(withIdentifier: "Nice Try", sender: btn) 
 } 
 print(button.restorationIdentifier!)
}

```

after that you can override prepare(for segue: UIStoryboardSegue, sender: Any?) for extra modification , inside (class scope) not in @IBAction

.
.
.
cellForRow:

* copy and replace your entire content code with this one:

```
  // if it's the First Collection View
  if collectionView == firstCV {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "firstCell", for: indexPath) as! FirstCollectionViewCell
      cell.buttonOne.setTitle(firstData[indexPath.item], for: []) //allows for button title change in code above
     cell.buttonOne.restorationIdentifier = "\(indexPath.row)"
      return cell  
  }

  // it's not the First Collection View, so it's the Second one
  let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "secondCell", for: indexPath) as! SecondCollectionViewCell
  cell.buttonTwo.setTitle(secondData[indexPath.item], for: [])
  cell.buttonTwo.restorationIdentifier = "\(indexPath.row + firstData.count)"
  return cell
  }

```